Browse files

Bring #reorder back

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 0a28073 commit fb215110401c70cfc7013c6e2ad5753fa4e374e9 @smartinez87 smartinez87 committed with spastorino Mar 28, 2011
View
2 activerecord/lib/active_record/base.rb
@@ -439,7 +439,7 @@ class Base
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
4 activerecord/lib/active_record/relation/query_methods.rb
@@ -62,6 +62,10 @@ def order(*args)
relation
end
+ def reorder(*args)
+ except(:order).order(args)
+ end
+
def joins(*args)
return self if args.compact.blank?
View
4 activerecord/test/cases/relation_scoping_test.rb
@@ -429,9 +429,9 @@ def test_scope_overwrites_default
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
6 activerecord/test/cases/relations_test.rb
@@ -151,6 +151,12 @@ def test_finding_with_order_concatenated
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

0 comments on commit fb21511

Please sign in to comment.