Skip to content

Commit

Permalink
Fix multiple self-referencing eager loads failing to join multiple times
Browse files Browse the repository at this point in the history
[#4679 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Ernie Miller authored and jeremy committed Jun 8, 2010
1 parent e404490 commit a4eaa1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -1903,7 +1903,7 @@ def initialize(active_record, joins = nil)
end

def ==(other)
other.is_a?(JoinBase) &&
other.class == self.class &&
other.active_record == active_record &&
other.table_joins == table_joins
end
Expand Down Expand Up @@ -1974,7 +1974,7 @@ def initialize(reflection, join_dependency, parent = nil)
end

def ==(other)
other.is_a?(JoinAssociation) &&
other.class == self.class &&
other.reflection == reflection &&
other.parent == parent
end
Expand Down
Expand Up @@ -7,9 +7,10 @@
require 'models/company'
require 'models/topic'
require 'models/reply'
require 'models/person'

class CascadedEagerLoadingTest < ActiveRecord::TestCase
fixtures :authors, :mixins, :companies, :posts, :topics, :accounts, :comments, :categorizations
fixtures :authors, :mixins, :companies, :posts, :topics, :accounts, :comments, :categorizations, :people

def test_eager_association_loading_with_cascaded_two_levels
authors = Author.find(:all, :include=>{:posts=>:comments}, :order=>"authors.id")
Expand Down Expand Up @@ -38,6 +39,13 @@ def test_eager_association_loading_with_hmt_does_not_table_name_collide_when_joi
assert_equal 9, assert_no_queries { authors[0].comments.size }
end

def test_eager_association_loading_grafts_stashed_associations_to_correct_parent
assert_nothing_raised do
Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').all
end
assert_equal people(:michael), Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').first
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
Expand Down

0 comments on commit a4eaa1f

Please sign in to comment.