mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Give preference to to_a over arel from Relation#method_missing
This commit is contained in:
parent
9465b84b54
commit
dbce07b81d
3 changed files with 12 additions and 5 deletions
|
@ -81,8 +81,8 @@ module ActiveRecord
|
|||
relation = self.class.unscoped
|
||||
|
||||
affected_rows = relation.where(
|
||||
relation[self.class.primary_key].eq(quoted_id).and(
|
||||
relation[self.class.locking_column].eq(quote_value(previous_value))
|
||||
relation.table[self.class.primary_key].eq(quoted_id).and(
|
||||
relation.table[self.class.locking_column].eq(quote_value(previous_value))
|
||||
)
|
||||
).update(arel_attributes_values(false, false, attribute_names))
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ module ActiveRecord
|
|||
include FinderMethods, Calculations, SpawnMethods, QueryMethods
|
||||
|
||||
delegate :length, :collect, :map, :each, :all?, :include?, :to => :to_a
|
||||
delegate :insert, :update, :where_clause, :to => :arel
|
||||
|
||||
attr_reader :table, :klass
|
||||
|
||||
|
@ -139,10 +140,10 @@ module ActiveRecord
|
|||
protected
|
||||
|
||||
def method_missing(method, *args, &block)
|
||||
if arel.respond_to?(method)
|
||||
arel.send(method, *args, &block)
|
||||
elsif Array.method_defined?(method)
|
||||
if Array.method_defined?(method)
|
||||
to_a.send(method, *args, &block)
|
||||
elsif arel.respond_to?(method)
|
||||
arel.send(method, *args, &block)
|
||||
elsif match = DynamicFinderMatch.match(method)
|
||||
attributes = match.attribute_names
|
||||
super unless @klass.send(:all_attributes_exists?, attributes)
|
||||
|
|
|
@ -379,6 +379,12 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
def test_deprecated_named_scope_method
|
||||
assert_deprecated('named_scope has been deprecated') { Topic.named_scope :deprecated_named_scope }
|
||||
end
|
||||
|
||||
def test_index_on_named_scope
|
||||
approved = Topic.approved.order('id ASC')
|
||||
assert_equal topics(:second), approved[0]
|
||||
assert approved.loaded?
|
||||
end
|
||||
end
|
||||
|
||||
class DynamicScopeMatchTest < ActiveRecord::TestCase
|
||||
|
|
Loading…
Reference in a new issue