aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-07-31 21:06:19 +0000
committerRick Olson <technoweenie@gmail.com>2006-07-31 21:06:19 +0000
commitab0277f22005b9690393318ef9adf94d815c1611 (patch)
tree3ba0194cfc0cae3eb23b126d3bb911a7aa3815b6 /activerecord/lib/active_record/associations/has_many_through_association.rb
parentd2eafa8b736c2f300658925e70290fb3d996959b (diff)
downloadrails-ab0277f22005b9690393318ef9adf94d815c1611.tar.gz
rails-ab0277f22005b9690393318ef9adf94d815c1611.tar.bz2
rails-ab0277f22005b9690393318ef9adf94d815c1611.zip
Calculate sum with SQL, not Enumerable on HasManyThrough Associations. [Dan Peterson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4640 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index c352a009d6..8f4ac104ad 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -47,7 +47,12 @@ module ActiveRecord
[:push, :concat, :create, :build].each do |method|
alias_method method, :<<
end
-
+
+ # Calculate sum using SQL, not Enumerable
+ def sum(*args, &block)
+ calculate(:sum, *args, &block)
+ end
+
protected
def method_missing(method, *args, &block)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))