diff options
author | Brian Lopez <seniorlopez@gmail.com> | 2010-04-30 14:59:41 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-05-04 11:57:52 -0700 |
commit | 7aad851c2e0d4579aa33a54a069a767b53cca406 (patch) | |
tree | a7a82d8e6dd69737da1e34630caa71f200200c62 /activerecord/lib | |
parent | 0dd3b4630fea4bd4d4010b7096c9ee79d34c4501 (diff) | |
download | rails-7aad851c2e0d4579aa33a54a069a767b53cca406.tar.gz rails-7aad851c2e0d4579aa33a54a069a767b53cca406.tar.bz2 rails-7aad851c2e0d4579aa33a54a069a767b53cca406.zip |
Allow pre-casted values (other than nil) to pass through from calculations un-touched
[#4514 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a5ea6e7e3a..8ab5eaa724 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -239,11 +239,15 @@ module ActiveRecord 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 |