1
0
Fork 0
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:
Rob Anderton 2009-03-09 12:51:55 +00:00 committed by Pratik Naik
parent 277c799d58
commit faf4ba6b79
2 changed files with 6 additions and 1 deletions

View file

@ -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)$/)

View file

@ -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)