提交 18d307ed 编写于 作者: S Samer Masry

Reverse order fix when using function for ActiveRecord::QueryMethods Fixes #1697

上级 fa2bfd83
......@@ -312,7 +312,7 @@ def reverse_sql_order(order_query)
when String, Symbol
o.to_s.split(',').collect do |s|
s.strip!
s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
(s if s =~ /\(/) || s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
end
else
o
......
......@@ -911,6 +911,11 @@ def test_default_scope_order_with_scope_order
assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name
end
def test_order_with_function_and_last
authors = Author.scoped
assert_equal authors(:bob), authors.order( "id asc, MAX( organization_id, owned_essay_id)" ).last
end
def test_order_using_scoping
car1 = CoolCar.order('id DESC').scoping do
CoolCar.find(:first, :order => 'id asc')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册