From 3b5c487f7e026be648d3eb605d6c3f115a14f5f1 Mon Sep 17 00:00:00 2001 From: Anatoliy Lysenko Date: Wed, 20 Oct 2010 08:45:34 +0300 Subject: [PATCH 1/3] Patch count with cascaded eager loading with joins. --- activerecord/lib/active_record/associations.rb | 5 ++--- .../associations/cascaded_eager_loading_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 59d328f..e774c70 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1849,7 +1849,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) || join_base, association.join_type) + build(association.reflection.name, association.find_parent_in(self), association.join_type) end self end @@ -2092,8 +2092,7 @@ module ActiveRecord def ==(other) other.class == self.class && - other.active_record == active_record && - other.table_joins == table_joins + other.active_record == active_record end def aliased_prefix diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb index c7c32da..e0a5f15 100644 --- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb @@ -45,6 +45,12 @@ 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 { categories.count } + end + def test_eager_association_loading_with_join_for_count authors = Author.joins(:special_posts).includes([:posts, :categorizations]) -- 1.7.0.4