Bring #reorder back
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
0a28073acc
commit
fb21511040
@ -439,7 +439,7 @@ class Base
|
|||||||
class << self # Class methods
|
class << self # Class methods
|
||||||
delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped
|
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 :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
|
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
|
# Executes a custom SQL query against your database and returns all the results. The results will
|
||||||
|
@ -62,6 +62,10 @@ def order(*args)
|
|||||||
relation
|
relation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reorder(*args)
|
||||||
|
except(:order).order(args)
|
||||||
|
end
|
||||||
|
|
||||||
def joins(*args)
|
def joins(*args)
|
||||||
return self if args.compact.blank?
|
return self if args.compact.blank?
|
||||||
|
|
||||||
|
@ -429,9 +429,9 @@ def test_scope_overwrites_default
|
|||||||
assert_equal expected, received
|
assert_equal expected, received
|
||||||
end
|
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 }
|
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
|
assert_equal expected, received
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -151,6 +151,12 @@ def test_finding_with_order_concatenated
|
|||||||
assert_equal topics(:fourth).title, topics.first.title
|
assert_equal topics(:fourth).title, topics.first.title
|
||||||
end
|
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
|
def test_finding_with_order_and_take
|
||||||
entrants = Entrant.order("id ASC").limit(2).to_a
|
entrants = Entrant.order("id ASC").limit(2).to_a
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user