aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/calculations.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2008-04-08 05:20:33 +0000
committerRick Olson <technoweenie@gmail.com>2008-04-08 05:20:33 +0000
commit78c2d9fc223e7a9945aee65c838f7ce78e9ddb3e (patch)
treea1e951f726d0831a75289d29396b7f7feb34f097 /activerecord/lib/active_record/calculations.rb
parent4d594cffcfc93b37fad4e423ec8593299e50133c (diff)
downloadrails-78c2d9fc223e7a9945aee65c838f7ce78e9ddb3e.tar.gz
rails-78c2d9fc223e7a9945aee65c838f7ce78e9ddb3e.tar.bz2
rails-78c2d9fc223e7a9945aee65c838f7ce78e9ddb3e.zip
ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9243 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/calculations.rb')
-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 490c8f4712..64527ec3f0 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -71,7 +71,7 @@ module ActiveRecord
#
# Person.sum('age')
def sum(column_name, options = {})
- calculate(:sum, column_name, options)
+ calculate(:sum, column_name, options) || 0
end
# This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts.