diff options
author | Vitalii Khustochka <xyctka@gmail.com> | 2010-07-12 14:17:48 +0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-13 08:31:55 +0200 |
commit | b75fca9e57423eec81384ff3e35f38fd4f7fe47f (patch) | |
tree | f6569ffc4371b7c931a0cd5afe31ec219eb5021f | |
parent | d2fae5f78efd7123b9ce633933f77cbe0e0711a9 (diff) | |
download | rails-b75fca9e57423eec81384ff3e35f38fd4f7fe47f.tar.gz rails-b75fca9e57423eec81384ff3e35f38fd4f7fe47f.tar.bz2 rails-b75fca9e57423eec81384ff3e35f38fd4f7fe47f.zip |
Added reorder delegation for ActiveRecord::Base(to be able to overwrite the default_scope ordering in the named scope [#5093 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r-- | activerecord/lib/active_record/base.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation_scoping_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 1 |
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index c78060c956..400a0adbcf 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -398,7 +398,7 @@ module ActiveRecord #:nodoc: delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped delegate :find_each, :find_in_batches, :to => :scoped - delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped + delegate :select, :group, :order, :reorder, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped delegate :count, :average, :minimum, :maximum, :sum, :calculate, :to => :scoped # Executes a custom SQL query against your database and returns all the results. The results will diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 41dcdbcd37..a5a3b3ef38 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -364,6 +364,12 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal expected, received end + def test_named_scope_reorders_default + expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.name } + received = DeveloperOrderedBySalary.reordered_by_name.find(:all).collect { |dev| dev.name } + assert_equal expected, received + end + def test_nested_exclusive_scope expected = Developer.find(:all, :limit => 100).collect { |dev| dev.salary } received = DeveloperOrderedBySalary.send(:with_exclusive_scope, :find => { :limit => 100 }) do diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index de68fd7f24..c61c583c1d 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -88,6 +88,7 @@ class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' default_scope :order => 'salary DESC' scope :by_name, :order => 'name DESC' + scope :reordered_by_name, reorder('name DESC') def self.all_ordered_by_name with_scope(:find => { :order => 'name DESC' }) do |