From afd4d8205e6a3264c30a29e4a2de0f1e71ef0717 Mon Sep 17 00:00:00 2001 From: Simon Woker Date: Thu, 10 Apr 2014 16:58:39 +0000 Subject: Fix error for aggregate methods with select, see issue #13648 --- activerecord/lib/active_record/relation.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 4d37ac6e2b..7cdae176a1 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -238,7 +238,7 @@ module ActiveRecord # Returns size of the records. def size - loaded? ? @records.length : count + loaded? ? @records.length : count(:all) end # Returns true if there are no records. @@ -248,8 +248,7 @@ module ActiveRecord if limit_value == 0 true else - # FIXME: This count is not compatible with #select('authors.*') or other select narrows - c = count + c = count(:all) c.respond_to?(:zero?) ? c.zero? : c.empty? end end -- cgit v1.2.3 From 70fffaccfc9761498cb50537d8b29c2e5d0585d1 Mon Sep 17 00:00:00 2001 From: Simon Woker Date: Fri, 11 Apr 2014 17:54:03 +0000 Subject: fix exception on polymorphic associations with predicates --- activerecord/lib/active_record/association_relation.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/association_relation.rb b/activerecord/lib/active_record/association_relation.rb index 20516bba0c..a17c36ccd9 100644 --- a/activerecord/lib/active_record/association_relation.rb +++ b/activerecord/lib/active_record/association_relation.rb @@ -8,7 +8,15 @@ module ActiveRecord def proxy_association @association end + + def size + @association.size + end + def empty? + @association.empty? + end + private def exec_queries -- cgit v1.2.3