diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-15 20:59:05 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-15 20:59:05 +0100 |
commit | 8854bf29a3590771aa989eb7e4b79f31eba9d96d (patch) | |
tree | 8be5054196116466d36211495ff27fecd5375ed1 /activerecord/lib/active_record | |
parent | b17bc58c76c580911e18f2dd90a17aaae192a2a3 (diff) | |
download | rails-8854bf29a3590771aa989eb7e4b79f31eba9d96d.tar.gz rails-8854bf29a3590771aa989eb7e4b79f31eba9d96d.tar.bz2 rails-8854bf29a3590771aa989eb7e4b79f31eba9d96d.zip |
Set up delegations also for to_a and arel branches.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/delegation.rb | 11 |
2 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 0f78fe1ab7..258c1959a0 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -132,13 +132,6 @@ module ActiveRecord first || new(attributes, options, &block) end - def respond_to?(method, include_private = false) - arel.respond_to?(method, include_private) || - Array.method_defined?(method) || - @klass.respond_to?(method, include_private) || - super - end - # Runs EXPLAIN on the query or queries triggered by this relation and # returns the result as a string. The string is formatted imitating the # ones printed by the database shell. diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index c1fcd48a8e..47fcc08550 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -2,9 +2,8 @@ require 'active_support/core_ext/module/delegation' module ActiveRecord module Delegation - # These are explicitly delegated to improve performance (avoids method_missing) + # Set up common delegations for performance (avoids method_missing) delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :to => :to_a - delegate :ast, :engine, :to => :arel delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :connection, :columns_hash, :auto_explain_threshold_in_seconds, :to => :klass @@ -24,15 +23,23 @@ module ActiveRecord end end + def respond_to?(method, include_private = false) + super || Array.method_defined?(method) || + @klass.respond_to?(method, include_private) || + arel.respond_to?(method, include_private) + end + protected def method_missing(method, *args, &block) if Array.method_defined?(method) + ::ActiveRecord::Delegation.delegate method, :to => :to_a to_a.send(method, *args, &block) elsif @klass.respond_to?(method) ::ActiveRecord::Delegation.delegate_to_scoped_klass(method) scoping { @klass.send(method, *args, &block) } elsif arel.respond_to?(method) + ::ActiveRecord::Delegation.delegate method, :to => :arel arel.send(method, *args, &block) else super |