Skip to content

Commit

Permalink
Merge pull request #47039 from ghiculescu/ar-relation-sum-money
Browse files Browse the repository at this point in the history
Make sure `ActiveRecord::Relation#sum` works with objects that implement #coerce without deprecation
  • Loading branch information
rafaelfranca committed Jan 18, 2023
2 parents db8bff6 + f3f97c2 commit 733c2ad
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -146,7 +146,7 @@ def async_maximum(column_name)
def sum(identity_or_column = nil, &block)
if block_given?
values = map(&block)
if identity_or_column.nil? && (values.first.is_a?(Numeric) || values.first(1) == [])
if identity_or_column.nil? && (values.first.is_a?(Numeric) || values.first(1) == [] || values.first.respond_to?(:coerce))
identity_or_column = 0
end

Expand Down

0 comments on commit 733c2ad

Please sign in to comment.