Skip to content

Commit

Permalink
Allow find(:last) :order be a symbol [#2024 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
rob-at-thewebfellas authored and lifo committed Mar 9, 2009
1 parent 277c799 commit faf4ba6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1537,7 +1537,7 @@ def find_last(options)
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)$/)
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1790,6 +1790,11 @@ def test_find_multiple_ordered_last
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)
Expand Down

0 comments on commit faf4ba6

Please sign in to comment.