mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #38641 from yashLadha/refactor/query_methods
refactor: Refactored code in functions of query_methods.
This commit is contained in:
commit
6a1759a085
1 changed files with 17 additions and 8 deletions
|
@ -1334,12 +1334,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def preprocess_order_args(order_args)
|
def preprocess_order_args(order_args)
|
||||||
order_args.reject!(&:blank?)
|
order_args = sanitize_order_arguments(order_args)
|
||||||
order_args.map! do |arg|
|
|
||||||
klass.sanitize_sql_for_order(arg)
|
|
||||||
end
|
|
||||||
order_args.flatten!
|
|
||||||
|
|
||||||
@klass.disallow_raw_sql!(
|
@klass.disallow_raw_sql!(
|
||||||
order_args.flat_map { |a| a.is_a?(Hash) ? a.keys : a },
|
order_args.flat_map { |a| a.is_a?(Hash) ? a.keys : a },
|
||||||
permit: connection.column_name_with_order_matcher
|
permit: connection.column_name_with_order_matcher
|
||||||
|
@ -1347,8 +1342,7 @@ module ActiveRecord
|
||||||
|
|
||||||
validate_order_args(order_args)
|
validate_order_args(order_args)
|
||||||
|
|
||||||
references = order_args.grep(String)
|
references = column_references(order_args)
|
||||||
references.map! { |arg| arg =~ /^\W?(\w+)\W?\./ && $1 }.compact!
|
|
||||||
references!(references) if references.any?
|
references!(references) if references.any?
|
||||||
|
|
||||||
# if a symbol is given we prepend the quoted table name
|
# if a symbol is given we prepend the quoted table name
|
||||||
|
@ -1371,6 +1365,21 @@ module ActiveRecord
|
||||||
end.flatten!
|
end.flatten!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize_order_arguments(order_args)
|
||||||
|
order_args.reject!(&:blank?)
|
||||||
|
order_args.map! do |arg|
|
||||||
|
klass.sanitize_sql_for_order(arg)
|
||||||
|
end
|
||||||
|
order_args.flatten!
|
||||||
|
order_args
|
||||||
|
end
|
||||||
|
|
||||||
|
def column_references(order_args)
|
||||||
|
references = order_args.grep(String)
|
||||||
|
references.map! { |arg| arg =~ /^\W?(\w+)\W?\./ && $1 }.compact!
|
||||||
|
references
|
||||||
|
end
|
||||||
|
|
||||||
def order_column(field)
|
def order_column(field)
|
||||||
arel_column(field) do |attr_name|
|
arel_column(field) do |attr_name|
|
||||||
if attr_name == "count" && !group_values.empty?
|
if attr_name == "count" && !group_values.empty?
|
||||||
|
|
Loading…
Reference in a new issue