Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set up delegations also for to_a and arel branches.

  • Loading branch information...
commit 8854bf29a3590771aa989eb7e4b79f31eba9d96d 1 parent b17bc58
@josevalim josevalim authored
View
7 activerecord/lib/active_record/relation.rb
@@ -132,13 +132,6 @@ def first_or_initialize(attributes = nil, options = {}, &block)
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.
View
11 activerecord/lib/active_record/relation/delegation.rb
@@ -2,9 +2,8 @@
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 @@ def #{method}(*args, &block)
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
Please sign in to comment.
Something went wrong with that request. Please try again.