Skip to content
Browse files

Merge pull request #2238 from cesario/order-with-extra-spaces

Ordering with extra spaces was raising a SQL exception
  • Loading branch information...
2 parents 1203451 + 77bb0b7 commit 02691d3516e68b2de5545ec7a495024a377f89fc @tenderlove tenderlove committed Jul 24, 2011
View
1 activerecord/lib/active_record/relation/query_methods.rb
@@ -311,6 +311,7 @@ def reverse_sql_order(order_query)
o.reverse
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')
end
else
View
4 activerecord/test/cases/relations_test.rb
@@ -961,4 +961,8 @@ def test_eager_loading_with_conditions_on_joins
assert scope.eager_loading?
end
+
+ def test_ordering_with_extra_spaces
+ assert_equal authors(:david), Author.order('organization_id ASC , owned_essay_id DESC').last
+ end
end

0 comments on commit 02691d3

Please sign in to comment.
Something went wrong with that request. Please try again.