aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-06-19 15:35:35 -0600
committerSean Griffin <sean@thoughtbot.com>2015-06-19 15:35:35 -0600
commitb644964b2b555798fc4b94d384b98438db863b3f (patch)
treeaf3a39838508d3cbce032b20b58889a62c607a05 /activerecord/lib/active_record/relation/calculations.rb
parent7d14bd3ff553d6aba11a50b43773bc21ae20f31e (diff)
downloadrails-b644964b2b555798fc4b94d384b98438db863b3f.tar.gz
rails-b644964b2b555798fc4b94d384b98438db863b3f.tar.bz2
rails-b644964b2b555798fc4b94d384b98438db863b3f.zip
Include `Enumerable` in `ActiveRecord::Relation`
After discussing, we've decided it makes more sense to include it. We're already forwarding every conflicting method to `to_a`, and there's no conflation of concerns. `Enumerable` has no mutating methods, and it just allows us to simplify the code. No existing methods will have a change in behavior. Un-overridden Enumerable methods will simply delegate to `each`. [Sean Griffin & bogdan]
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb9
1 files changed, 3 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 29cc79db1b..7108b087f1 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -70,12 +70,9 @@ module ActiveRecord
# +calculate+ for examples with options.
#
# Person.sum(:age) # => 4562
- def sum(*args, &block)
- if block_given?
- to_a.sum(&block)
- else
- calculate(:sum, *args)
- end
+ def sum(*args)
+ return super if block_given?
+ calculate(:sum, *args)
end
# This calculates aggregate values in the given column. Methods for count, sum, average,