convert order arg to string before checking if we can reverse it
This commit is contained in:
parent
ab03eb9f57
commit
c711a27d29
@ -1097,6 +1097,10 @@ def reverse_sql_order(order_query)
|
||||
end
|
||||
|
||||
def does_not_support_reverse?(order)
|
||||
# Account for String subclasses like Arel::Nodes::SqlLiteral that
|
||||
# override methods like #count.
|
||||
order = String.new(order) unless order.instance_of?(String)
|
||||
|
||||
# Uses SQL function with multiple arguments.
|
||||
(order.include?(",") && order.split(",").find { |section| section.count("(") != section.count(")") }) ||
|
||||
# Uses "nulls first" like construction.
|
||||
|
@ -248,9 +248,9 @@ def test_reverse_arel_assoc_order_with_function
|
||||
end
|
||||
|
||||
def test_reverse_order_with_function_other_predicates
|
||||
topics = Topic.order("author_name, length(title), id").reverse_order
|
||||
topics = Topic.order(Arel.sql("author_name, length(title), id")).reverse_order
|
||||
assert_equal topics(:second).title, topics.first.title
|
||||
topics = Topic.order("length(author_name), id, length(title)").reverse_order
|
||||
topics = Topic.order(Arel.sql("length(author_name), id, length(title)")).reverse_order
|
||||
assert_equal topics(:fifth).title, topics.first.title
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user