aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-05-30 06:57:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-05-30 06:57:04 +0000
commit1f802968c5a803f649fc27c7295b01aef3af6514 (patch)
tree4557d9ca4f873877824aa91a74ee5b2d9d828a86 /activerecord/lib/active_record
parentb2681cca2e38b7465cd94d51dde14e53b724d0d1 (diff)
downloadrails-1f802968c5a803f649fc27c7295b01aef3af6514.tar.gz
rails-1f802968c5a803f649fc27c7295b01aef3af6514.tar.bz2
rails-1f802968c5a803f649fc27c7295b01aef3af6514.zip
Calculations: return nil average instead of 0 when there are no rows to average. Closes #8298.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6904 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/calculations.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb
index a54ef468e0..09c0c979e6 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -265,7 +265,7 @@ module ActiveRecord
operation = operation.to_s.downcase
case operation
when 'count' then value.to_i
- when 'avg' then value.to_f
+ when 'avg' then value && value.to_f
else column ? column.type_cast(value) : value
end
end