diff options
author | Frederick Cheung <frederick.cheung@gmail.com> | 2008-12-19 01:02:21 +0000 |
---|---|---|
committer | Frederick Cheung <frederick.cheung@gmail.com> | 2008-12-26 18:25:55 +0000 |
commit | 5cebe69e74d411c3c9e5f6ab9d4b2b16ee36177c (patch) | |
tree | 7e30226bcda0e5f9292b71927a32d5c15133e391 /activerecord/test/cases | |
parent | eb457ceee13779ade67e1bdebd2919d476148277 (diff) | |
download | rails-5cebe69e74d411c3c9e5f6ab9d4b2b16ee36177c.tar.gz rails-5cebe69e74d411c3c9e5f6ab9d4b2b16ee36177c.tar.bz2 rails-5cebe69e74d411c3c9e5f6ab9d4b2b16ee36177c.zip |
Preload uses exclusive scope [#643 state:resolved]
With self referential associations, the scope for the the top level should not affect fetching of associations, for example
when doing
Person.male.find :all, :include => :friends
we should load all of the friends for each male, not just the male friends.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index a2d0efab92..afbd9fddf9 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -771,4 +771,19 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal author_addresses(:david_address), authors[0].author_address end + def test_preload_belongs_to_uses_exclusive_scope + people = Person.males.find(:all, :include => :primary_contact) + assert_not_equal people.length, 0 + people.each do |person| + assert_no_queries {assert_not_nil person.primary_contact} + assert_equal Person.find(person.id).primary_contact, person.primary_contact + end + end + + def test_preload_has_many_uses_exclusive_scope + people = Person.males.find :all, :include => :agents + people.each do |person| + assert_equal Person.find(person.id).agents, person.agents + end + end end |