Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added reorder delegation for ActiveRecord::Base(to be able to overwri…

…te the default_scope ordering in the named scope [#5093 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit b75fca9e57423eec81384ff3e35f38fd4f7fe47f 1 parent d2fae5f
@khustochka khustochka authored josevalim committed
View
2  activerecord/lib/active_record/base.rb
@@ -398,7 +398,7 @@ def colorize_logging(*args)
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
View
6 activerecord/test/cases/relation_scoping_test.rb
@@ -364,6 +364,12 @@ def test_named_scope_overwrites_default
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
View
1  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
Please sign in to comment.
Something went wrong with that request. Please try again.