mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Set up delegations also for to_a and arel branches.
This commit is contained in:
parent
b17bc58c76
commit
8854bf29a3
2 changed files with 9 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue