diff options
author | Marcelo Casiraghi <marcelocasiraghi@gmail.com> | 2013-05-23 00:17:15 -0300 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2014-03-04 18:20:00 +0100 |
commit | acbd7ab22e5d9179487bd98110234c54535036c4 (patch) | |
tree | a84e1a5205de1e33dc635dffb0dc8bd48e8542e0 /activerecord/lib/active_record/relation/query_methods.rb | |
parent | 705915ab5cf24430892107764b0050c07e1df583 (diff) | |
download | rails-acbd7ab22e5d9179487bd98110234c54535036c4.tar.gz rails-acbd7ab22e5d9179487bd98110234c54535036c4.tar.bz2 rails-acbd7ab22e5d9179487bd98110234c54535036c4.zip |
Allow string hash values on AR order method
This behavior has almost no performance impact:
String not allowed 66.910000 0.030000 66.940000 ( 67.024976)
String allowed 69.360000 0.030000 69.390000 ( 69.503096)
Benchmarked with http://git.io/Y0YuRw.
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index d88858611c..a22849f4a6 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1030,10 +1030,13 @@ module ActiveRecord arel.order(*orders) unless orders.empty? end + VALID_DIRECTIONS = [:asc, :desc, 'asc', 'desc'] # :nodoc: + def validate_order_args(args) args.grep(Hash) do |h| - unless (h.values - [:asc, :desc]).empty? - raise ArgumentError, 'Direction should be :asc or :desc' + h.values.map(&:downcase).each do |value| + raise ArgumentError, "Direction '#{value}' is invalid. Valid " \ + "directions are asc and desc." unless VALID_DIRECTIONS.include?(value) end end end @@ -1055,7 +1058,7 @@ module ActiveRecord when Hash arg.map { |field, dir| field = klass.attribute_alias(field) if klass.attribute_alias?(field) - table[field].send(dir) + table[field].send(dir.downcase) } else arg |