aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
authorBen Toews <mastahyeti@gmail.com>2017-10-18 10:21:45 -0600
committerMatthew Draper <matthew@trebex.net>2017-11-09 22:42:15 +1030
commit8ef71ac4a119a4c03d78db2372b41ddcc8a95035 (patch)
tree69133ce1a019e79f121559d3e4fdf71b760c5148 /activerecord/lib/active_record/relation/query_methods.rb
parentb76cc29865fb69389ffdb7bd9f8085aa86354f82 (diff)
downloadrails-8ef71ac4a119a4c03d78db2372b41ddcc8a95035.tar.gz
rails-8ef71ac4a119a4c03d78db2372b41ddcc8a95035.tar.bz2
rails-8ef71ac4a119a4c03d78db2372b41ddcc8a95035.zip
push order arg checks down to allow for binds
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb33
1 files changed, 6 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 1dcd786498..cef0847651 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -297,11 +297,6 @@ module ActiveRecord
# Same as #order but operates on relation in-place instead of copying.
def order!(*args) # :nodoc:
- @klass.enforce_raw_sql_whitelist(
- column_names_from_order_arguments(args),
- whitelist: AttributeMethods::ClassMethods::COLUMN_NAME_ORDER_WHITELIST
- )
-
preprocess_order_args(args)
self.order_values += args
@@ -324,11 +319,6 @@ module ActiveRecord
# Same as #reorder but operates on relation in-place instead of copying.
def reorder!(*args) # :nodoc:
- @klass.enforce_raw_sql_whitelist(
- column_names_from_order_arguments(args),
- whitelist: AttributeMethods::ClassMethods::COLUMN_NAME_ORDER_WHITELIST
- )
-
preprocess_order_args(args)
self.reordering_value = true
@@ -928,23 +918,6 @@ module ActiveRecord
private
- # Extract column names from arguments passed to #order or #reorder.
- def column_names_from_order_arguments(args)
- args.flat_map do |arg|
- case arg
- when Hash
- # Tag.order(id: :desc)
- arg.keys
- when Array
- # Tag.order([Arel.sql("field(id, ?)"), [1, 3, 2]])
- arg.flatten
- else
- # Tag.order(:id)
- arg
- end
- end
- end
-
def assert_mutability!
raise ImmutableRelation if @loaded
raise ImmutableRelation if defined?(@arel) && @arel
@@ -1146,6 +1119,12 @@ module ActiveRecord
klass.send(:sanitize_sql_for_order, arg)
end
order_args.flatten!
+
+ @klass.enforce_raw_sql_whitelist(
+ order_args.flat_map { |a| a.is_a?(Hash) ? a.keys : a },
+ whitelist: AttributeMethods::ClassMethods::COLUMN_NAME_ORDER_WHITELIST
+ )
+
validate_order_args(order_args)
references = order_args.grep(String)