Permalink
Browse files

JoinDependency#graft does not properly set parent join [#5124 state:r…

…esolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 181e0d3 commit 1fcf4e8ecbe4db2443a88d1e06c06667cff5b762 David Genord II committed with lifo Jul 13, 2010
View
2 activerecord/lib/active_record/associations.rb
@@ -1761,7 +1761,7 @@ def initialize(base, associations, joins)
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
View
7 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -46,6 +46,13 @@ def test_eager_association_loading_grafts_stashed_associations_to_correct_parent
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
@bamnet
bamnet Jul 16, 2010

Typo on association.

Probably meant to be test_eager_association_loading_with_join_for_count.

@tenderlove
tenderlove Jul 16, 2010

Thanks! Fixed here: 1b2824b

+ 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

0 comments on commit 1fcf4e8

Please sign in to comment.