1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #40194 from kddeisz/nulls-firstlast-reverse

Properly support `reverse_order` on relations with `nulls_first` or `nulls_last` calls
This commit is contained in:
Eugene Kenny 2020-09-08 16:53:18 +01:00 committed by GitHub
commit 015c393285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -12,7 +12,16 @@ module Arel # :nodoc: all
end
end
class NullsFirst < Ordering; end
class NullsLast < Ordering; end
class NullsFirst < Ordering
def reverse
NullsLast.new(expr.reverse)
end
end
class NullsLast < Ordering
def reverse
NullsFirst.new(expr.reverse)
end
end
end
end

View file

@ -330,6 +330,20 @@ module Arel
"users"."first_name" DESC NULLS LAST
}
end
it "should handle nulls first reversed" do
test = Table.new(:users)[:first_name].desc.nulls_first.reverse
_(compile(test)).must_be_like %{
"users"."first_name" ASC NULLS LAST
}
end
it "should handle nulls last reversed" do
test = Table.new(:users)[:first_name].desc.nulls_last.reverse
_(compile(test)).must_be_like %{
"users"."first_name" ASC NULLS FIRST
}
end
end
describe "Nodes::InfixOperation" do