diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-06-22 08:30:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-06-22 08:30:52 -0700 |
commit | 09866cef1796774654a27dcb550ad563feddc531 (patch) | |
tree | 3439ce07773c73d45adf6a9e4020ec78e4f737e1 /activerecord/lib | |
parent | 5654f6870af3cfb7dd92a017e7f86ba40ebfd9bf (diff) | |
parent | 08f3f30994d37f6f44acfac801f82fc43127fc78 (diff) | |
download | rails-09866cef1796774654a27dcb550ad563feddc531.tar.gz rails-09866cef1796774654a27dcb550ad563feddc531.tar.bz2 rails-09866cef1796774654a27dcb550ad563feddc531.zip |
Merge pull request #1790 from ernie/reverse_sql_order_fix
Support reversal of ARel orderings in reverse_sql_order
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 739363415c..7fbbefeea2 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -305,9 +305,18 @@ module ActiveRecord def reverse_sql_order(order_query) order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty? - order_query.join(', ').split(',').collect do |s| - s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') - end + order_query.map do |o| + case o + when Arel::Nodes::Ordering + o.reverse + when String, Symbol + o.to_s.split(',').collect do |s| + s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') + end + else + o + end + end.flatten end def array_of_strings?(o) |