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:
commit
015c393285
2 changed files with 25 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue