Skip to content

Commit

Permalink
Ordering with extra spaces was raising a SQL exception
Browse files Browse the repository at this point in the history
  • Loading branch information
franckverrot committed Jul 24, 2011
1 parent d33eb07 commit 77bb0b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -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 77bb0b7

Please sign in to comment.