aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Genord II <david@xspond.com>2010-07-13 18:14:26 -0400
committerPratik Naik <pratiknaik@gmail.com>2010-07-16 08:28:49 +0100
commit1fcf4e8ecbe4db2443a88d1e06c06667cff5b762 (patch)
tree8c7a7be386fdcc139142f9e5d7526dcfc4638119 /activerecord
parent181e0d326de8ce212d951d0e8a8ca0ba478ac5a4 (diff)
downloadrails-1fcf4e8ecbe4db2443a88d1e06c06667cff5b762.tar.gz
rails-1fcf4e8ecbe4db2443a88d1e06c06667cff5b762.tar.bz2
rails-1fcf4e8ecbe4db2443a88d1e06c06667cff5b762.zip
JoinDependency#graft does not properly set parent join [#5124 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb2
-rw-r--r--activerecord/test/cases/associations/cascaded_eager_loading_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 9fe8d54f02..d67df64f59 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1761,7 +1761,7 @@ module ActiveRecord
def graft(*associations)
associations.each do |association|
join_associations.detect {|a| association == a} ||
- build(association.reflection.name, association.find_parent_in(self), association.join_class)
+ build(association.reflection.name, association.find_parent_in(self) || join_base, association.join_class)
end
self
end
diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
index 9c5dcc2ad9..67eb6403c8 100644
--- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
+++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -46,6 +46,13 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
assert_equal people(:michael), Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').order('people.id').first
end
+ def test_eager_associatoin_loading_with_join_for_count
+ authors = Author.joins(:special_posts).includes([:posts, :categorizations])
+
+ assert_nothing_raised { authors.count }
+ assert_queries(3) { authors.all }
+ end
+
def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
authors = Author.find(:all, :include=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id")
assert_equal 2, authors.size