mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow find(:last) :order be a symbol [#2024 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
277c799d58
commit
faf4ba6b79
2 changed files with 6 additions and 1 deletions
|
@ -1537,7 +1537,7 @@ module ActiveRecord #:nodoc:
|
|||
end
|
||||
|
||||
def reverse_sql_order(order_query)
|
||||
reversed_query = order_query.split(/,/).each { |s|
|
||||
reversed_query = order_query.to_s.split(/,/).each { |s|
|
||||
if s.match(/\s(asc|ASC)$/)
|
||||
s.gsub!(/\s(asc|ASC)$/, ' DESC')
|
||||
elsif s.match(/\s(desc|DESC)$/)
|
||||
|
|
|
@ -1790,6 +1790,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
assert_equal last, Developer.find(:all, :order => 'developers.name, developers.salary DESC').last
|
||||
end
|
||||
|
||||
def test_find_symbol_ordered_last
|
||||
last = Developer.find :last, :order => :salary
|
||||
assert_equal last, Developer.find(:all, :order => :salary).last
|
||||
end
|
||||
|
||||
def test_find_scoped_ordered_last
|
||||
last_developer = Developer.with_scope(:find => { :order => 'developers.salary ASC' }) do
|
||||
Developer.find(:last)
|
||||
|
|
Loading…
Reference in a new issue