1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Bring #reorder back

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
Sebastian Martinez 2011-03-28 10:19:41 -03:00 committed by Santiago Pastorino
parent 0a28073acc
commit fb21511040
4 changed files with 13 additions and 3 deletions

View file

@ -439,7 +439,7 @@ module ActiveRecord #:nodoc:
class << self # Class methods
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, :except, :limit, :offset, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped
delegate :select, :group, :order, :except, :reorder, :limit, :offset, :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 file

@ -62,6 +62,10 @@ module ActiveRecord
relation
end
def reorder(*args)
except(:order).order(args)
end
def joins(*args)
return self if args.compact.blank?

View file

@ -429,9 +429,9 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected, received
end
def test_except_and_order_overrides_default_scope_order
def test_reorder_overrides_default_scope_order
expected = Developer.order('name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.except(:order).order('name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.reorder('name DESC').collect { |dev| dev.name }
assert_equal expected, received
end

View file

@ -151,6 +151,12 @@ class RelationTest < ActiveRecord::TestCase
assert_equal topics(:fourth).title, topics.first.title
end
def test_finding_with_reorder
topics = Topic.order('author_name').order('title').reorder('id').all
topics_titles = topics.map{ |t| t.title }
assert_equal ['The First Topic', 'The Second Topic of the day', 'The Third Topic of the day', 'The Fourth Topic of the day'], topics_titles
end
def test_finding_with_order_and_take
entrants = Entrant.order("id ASC").limit(2).to_a