diff options
author | Rick Olson <technoweenie@gmail.com> | 2008-02-14 07:24:09 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2008-02-14 07:24:09 +0000 |
commit | 8a2266c02063c1111c666c71ced7822f095ed56c (patch) | |
tree | 1420ac25830d4e1f8da1c1035369b703617f4ed0 /activerecord/lib/active_record/associations/has_many_through_association.rb | |
parent | dfa786631bb8476c8cae555ad8de5e83811dfe9d (diff) | |
download | rails-8a2266c02063c1111c666c71ced7822f095ed56c.tar.gz rails-8a2266c02063c1111c666c71ced7822f095ed56c.tar.bz2 rails-8a2266c02063c1111c666c71ced7822f095ed56c.zip |
Improve associations performance by avoiding named block arguments. Closes #11109
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8865 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.rb | 12 |
1 files changed, 7 insertions, 5 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 94842f424d..23931bcda2 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -113,8 +113,8 @@ module ActiveRecord end # Calculate sum using SQL, not Enumerable - def sum(*args, &block) - calculate(:sum, *args, &block) + def sum(*args) + calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } end def count(*args) @@ -128,11 +128,13 @@ module ActiveRecord end protected - def method_missing(method, *args, &block) + def method_missing(method, *args) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super + super { |*block_args| yield(*block_args) if block_given? } else - @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } + @reflection.klass.send(:with_scope, construct_scope) { + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } + } end end |