diff options
author | Ernie Miller <ernie@metautonomo.us> | 2010-10-20 22:54:43 -0400 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-30 06:48:44 -0700 |
commit | 0bb85ed9ffa9808926b46e8f7e59cab5b85ac19f (patch) | |
tree | ce704699ba926f315a080963f4d094d44ee60cf0 /activerecord/test | |
parent | b82fab25f999dd6245c23a22f948048eef2d5d9a (diff) | |
download | rails-0bb85ed9ffa9808926b46e8f7e59cab5b85ac19f.tar.gz rails-0bb85ed9ffa9808926b46e8f7e59cab5b85ac19f.tar.bz2 rails-0bb85ed9ffa9808926b46e8f7e59cab5b85ac19f.zip |
Fix issues when including the same association multiple times and mixing joins/includes together.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/cascaded_eager_loading_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb index c7c32da9f3..271bb92ee8 100644 --- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb @@ -3,6 +3,7 @@ require 'models/post' require 'models/comment' require 'models/author' require 'models/categorization' +require 'models/category' require 'models/company' require 'models/topic' require 'models/reply' @@ -45,6 +46,31 @@ 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_cascaded_eager_association_loading_with_join_for_count + categories = Category.joins(:categorizations).includes([{:posts=>:comments}, :authors]) + + assert_nothing_raised do + assert_equal 2, categories.count + assert_equal 2, categories.all.uniq.size # Must uniq since instantiating with inner joins will get dupes + end + end + + def test_cascaded_eager_association_loading_with_duplicated_includes + categories = Category.includes(:categorizations).includes(:categorizations => :author).where("categorizations.id is not null") + assert_nothing_raised do + assert_equal 2, categories.count + assert_equal 2, categories.all.size + end + end + + def test_cascaded_eager_association_loading_with_twice_includes_edge_cases + categories = Category.includes(:categorizations => :author).includes(:categorizations => :post).where("posts.id is not null") + assert_nothing_raised do + assert_equal 2, categories.count + assert_equal 2, categories.all.size + end + end + def test_eager_association_loading_with_join_for_count authors = Author.joins(:special_posts).includes([:posts, :categorizations]) |