aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2017-03-12 18:10:59 +0000
committerGitHub <noreply@github.com>2017-03-12 18:10:59 +0000
commit097612e8f5bc520bbcdd3c9134a3421eac4d624a (patch)
treee30d5e9d46f7672cf6dcaa4f3fdac490452163ee /activerecord
parent89d66410892b9c42bf2a11f7308d6c8bf8d656c8 (diff)
parentc4c8d808d0054dff9bf6e783638b8ea2f3499da1 (diff)
downloadrails-097612e8f5bc520bbcdd3c9134a3421eac4d624a.tar.gz
rails-097612e8f5bc520bbcdd3c9134a3421eac4d624a.tar.bz2
rails-097612e8f5bc520bbcdd3c9134a3421eac4d624a.zip
Merge pull request #28371 from kamipo/simplify_count
Simply forward `Calculations#count` to `Enumerable#count`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb11
1 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index f4cdaf3948..9cabd1af13 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -37,11 +37,8 @@ module ActiveRecord
# Note: not all valid {Relation#select}[rdoc-ref:QueryMethods#select] expressions are valid #count expressions. The specifics differ
# between databases. In invalid cases, an error from the database is thrown.
def count(column_name = nil)
- if block_given?
- to_a.count { |*block_args| yield(*block_args) }
- else
- calculate(:count, column_name)
- end
+ return super() if block_given?
+ calculate(:count, column_name)
end
# Calculates the average value on a given column. Returns +nil+ if there's
@@ -75,8 +72,8 @@ module ActiveRecord
# #calculate for examples with options.
#
# Person.sum(:age) # => 4562
- def sum(column_name = nil, &block)
- return super(&block) if block_given?
+ def sum(column_name = nil)
+ return super() if block_given?
calculate(:sum, column_name)
end