From 8854bf29a3590771aa989eb7e4b79f31eba9d96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 20:59:05 +0100 Subject: Set up delegations also for to_a and arel branches. --- activerecord/lib/active_record/relation.rb | 7 ------- activerecord/lib/active_record/relation/delegation.rb | 11 +++++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3