Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for get_ids when including a belongs_to association on a has_many…

… association [#2896 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 3436fdfc12d58925e3d981e0afa61084ea34736c 1 parent 2d84f24
@oboxodo oboxodo authored lifo committed
View
2  activerecord/lib/active_record/associations.rb
@@ -1398,7 +1398,7 @@ def collection_reader_method(reflection, association_proxy_class)
primary_key = reflection.source_reflection.primary_key_name
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").map!(&:"#{primary_key}")
else
- send(reflection.name).select("#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").map!(&:id)
+ send(reflection.name).select("#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").except(:includes).map!(&:id)
end
end
end
View
4 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -900,6 +900,10 @@ def test_get_ids_for_unloaded_associations_does_not_load_them
assert !company.clients.loaded?
end
+ def test_get_ids_ignores_include_option
+ assert_equal [readers(:michael_welcome).id], posts(:welcome).readers_with_person_ids
+ end
+
def test_get_ids_for_unloaded_finder_sql_associations_loads_them
company = companies(:first_firm)
assert !company.clients_using_sql.loaded?
View
1  activerecord/test/models/post.rb
@@ -69,6 +69,7 @@ def add_joins_and_select
has_many :authors, :through => :categorizations
has_many :readers
+ has_many :readers_with_person, :include => :person, :class_name => "Reader"
has_many :people, :through => :readers
has_many :people_with_callbacks, :source=>:person, :through => :readers,
:before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
Please sign in to comment.
Something went wrong with that request. Please try again.