mirror of https://github.com/rails/rails
Merge pull request #35274 from AlexBrodianoi/fix_does_not_support_reverse
Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a single ordering argument.
This commit is contained in:
commit
5ca19efafe
|
@ -1111,7 +1111,7 @@ module ActiveRecord
|
|||
# Uses SQL function with multiple arguments.
|
||||
(order.include?(",") && order.split(",").find { |section| section.count("(") != section.count(")") }) ||
|
||||
# Uses "nulls first" like construction.
|
||||
/nulls (first|last)\Z/i.match?(order)
|
||||
/\bnulls\s+(?:first|last)\b/i.match?(order)
|
||||
end
|
||||
|
||||
def build_order(arel)
|
||||
|
|
|
@ -290,9 +290,18 @@ class RelationTest < ActiveRecord::TestCase
|
|||
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
||||
Topic.order(Arel.sql("title NULLS FIRST")).reverse_order
|
||||
end
|
||||
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
||||
Topic.order(Arel.sql("title NULLS FIRST")).reverse_order
|
||||
end
|
||||
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
||||
Topic.order(Arel.sql("title nulls last")).reverse_order
|
||||
end
|
||||
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
||||
Topic.order(Arel.sql("title NULLS FIRST, author_name")).reverse_order
|
||||
end
|
||||
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
||||
Topic.order(Arel.sql("author_name, title nulls last")).reverse_order
|
||||
end
|
||||
end
|
||||
|
||||
def test_default_reverse_order_on_table_without_primary_key
|
||||
|
|
Loading…
Reference in New Issue