aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2010-05-22 15:31:06 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2010-06-08 01:02:19 -0400
commita4eaa1fd39f93eff975bfd8a5cc4c7dfc3f18aa7 (patch)
treeaa4ec34ceab2d5121e52126fd6a04c7be4505a0c /activerecord/test
parente404490f9bae102f8c7126917d59568e6d1fef79 (diff)
downloadrails-a4eaa1fd39f93eff975bfd8a5cc4c7dfc3f18aa7.tar.gz
rails-a4eaa1fd39f93eff975bfd8a5cc4c7dfc3f18aa7.tar.bz2
rails-a4eaa1fd39f93eff975bfd8a5cc4c7dfc3f18aa7.zip
Fix multiple self-referencing eager loads failing to join multiple times
[#4679 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/cascaded_eager_loading_test.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
index fe558f9d3b..7a4a33d177 100644
--- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
+++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -7,9 +7,10 @@ require 'models/categorization'
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")
@@ -38,6 +39,13 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
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