Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow pre-casted values (other than nil) to pass through from calcula…

…tions un-touched

[#4514 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 6dbc75fd7625c0248d269cc3127910cb4c888ed9 1 parent 04fa5af
@brianmario brianmario authored jeremy committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 activerecord/lib/active_record/calculations.rb
View
9 activerecord/lib/active_record/calculations.rb
@@ -294,12 +294,15 @@ def column_for(field)
end
def type_cast_calculated_value(value, column, operation = nil)
- operation = operation.to_s.downcase
- case operation
+ if value.is_a?(String) || value.nil?
+ case operation.to_s.downcase
when 'count' then value.to_i
when 'sum' then type_cast_using_column(value || '0', column)
- when 'avg' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
+ when 'avg' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
else type_cast_using_column(value, column)
+ end
+ else
+ value
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.