diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 22:52:08 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 22:52:08 +0530 |
commit | dbce07b81d24a991ddd29b91f9c358b1f236bda2 (patch) | |
tree | d2d3e5f5ebce075311fa1ab22e7749e7549879c7 | |
parent | 9465b84b543ae1ada29c0e39e34f919c724eab6d (diff) | |
download | rails-dbce07b81d24a991ddd29b91f9c358b1f236bda2.tar.gz rails-dbce07b81d24a991ddd29b91f9c358b1f236bda2.tar.bz2 rails-dbce07b81d24a991ddd29b91f9c358b1f236bda2.zip |
Give preference to to_a over arel from Relation#method_missing
-rw-r--r-- | activerecord/lib/active_record/locking/optimistic.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 6 |
3 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 9fcdabdb44..bf0683eb8f 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -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)) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 6ac7137976..8bb019f147 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -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) diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 3e2bd58f9a..2c34ab787d 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -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 |