aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-03-05 09:05:15 +0100
committerYves Senn <yves.senn@gmail.com>2014-03-05 09:05:15 +0100
commit5f7f3bb1df6eb45232e8399611158972ad53ec69 (patch)
tree96f12d8dfc7ed9c8d99f13f3a352a434d349b1be /activerecord/lib/active_record/relation
parentef7e7ad7e9c11916865b7e3e9f0c754a4e6fc775 (diff)
parentacbd7ab22e5d9179487bd98110234c54535036c4 (diff)
downloadrails-5f7f3bb1df6eb45232e8399611158972ad53ec69.tar.gz
rails-5f7f3bb1df6eb45232e8399611158972ad53ec69.tar.bz2
rails-5f7f3bb1df6eb45232e8399611158972ad53ec69.zip
Merge pull request #14263 from robin850/allow_passing_string_to_order_hash
Follow up of #10732 - Allow string hash values on AR order method
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb9
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