提交 faf4ba6b 编写于 作者: R Rob Anderton 提交者: Pratik Naik

Allow find(:last) :order be a symbol [#2024 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 277c799d
......@@ -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)$/)
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册