Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply forward Calculations#count to Enumerable#count #28371

Merged
merged 1 commit into from
Mar 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions activerecord/lib/active_record/relation/calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ module Calculations
# 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
Expand Down Expand Up @@ -75,8 +72,8 @@ def maximum(column_name)
# #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

Expand Down