Skip to content

Commit

Permalink
Fix for get_ids when including a belongs_to association on a has_many…
Browse files Browse the repository at this point in the history
… association [#2896 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
oboxodo authored and lifo committed May 15, 2010
1 parent 2d84f24 commit 3436fdf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -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
Expand Down
Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/models/post.rb
Expand Up @@ -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) },
Expand Down

0 comments on commit 3436fdf

Please sign in to comment.