Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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 7aad851c2e0d4579aa33a54a069a767b53cca406 1 parent 0dd3b46
@brianmario brianmario authored jeremy committed
Showing with 9 additions and 5 deletions.
  1. +9 −5 activerecord/lib/active_record/relation/calculations.rb
View
14 activerecord/lib/active_record/relation/calculations.rb
@@ -239,11 +239,15 @@ def column_for(field)
end
def type_cast_calculated_value(value, column, operation = nil)
- case operation
- when 'count' then value.to_i
- when 'sum' then type_cast_using_column(value || '0', column)
- when 'average' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
- else type_cast_using_column(value, column)
+ if value.is_a?(String) || value.nil?
+ case operation
+ when 'count' then value.to_i
+ when 'sum' then type_cast_using_column(value || '0', column)
+ when 'average' 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.