aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-11 15:13:36 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-11 15:13:36 -0300
commitd447eef20b674b3fb5da4429af6ee23233ef3d8a (patch)
tree8d5ba7e5a1e5e87eb12bf918bc7f1d00233ed61e /activerecord/lib/active_record
parent7bb8fd2f641c3416522e647ed32a3142ccc1e01b (diff)
parent70fffaccfc9761498cb50537d8b29c2e5d0585d1 (diff)
downloadrails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.tar.gz
rails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.tar.bz2
rails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.zip
Merge pull request #14711 from swoker/activerecord_fix_aggregate_methods_with_select
Activerecord fix aggregate methods with select
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/association_relation.rb8
-rw-r--r--activerecord/lib/active_record/relation.rb5
2 files changed, 10 insertions, 3 deletions
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
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 787f55e2e7..d1764a2bb2 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