Browse files

Merge pull request #2309 from smasry/master

Unmangaling reverse_sql_order when function is used
  • Loading branch information...
2 parents fa2bfd8 + 18d307e commit 9d396ee8195e31f646e0b89158ed96f4db4ab38f @tenderlove tenderlove committed Jul 27, 2011
View
2 activerecord/lib/active_record/relation/query_methods.rb
@@ -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
View
5 activerecord/test/cases/relations_test.rb
@@ -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')

0 comments on commit 9d396ee

Please sign in to comment.