mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add SelectManager#distinct_on to set/unset Arel::Nodes::DistinctOn quantifier
This commit is contained in:
parent
36836fa5e7
commit
112cb940aa
2 changed files with 30 additions and 0 deletions
|
@ -155,6 +155,15 @@ module Arel
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def distinct_on(value)
|
||||||
|
if value
|
||||||
|
@ctx.set_quantifier = Arel::Nodes::DistinctOn.new(value)
|
||||||
|
else
|
||||||
|
@ctx.set_quantifier = nil
|
||||||
|
end
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def order *expr
|
def order *expr
|
||||||
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
|
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
|
||||||
@ast.orders.concat expr.map { |x|
|
@ast.orders.concat expr.map { |x|
|
||||||
|
|
|
@ -1158,5 +1158,26 @@ module Arel
|
||||||
manager.distinct(false).must_equal manager
|
manager.distinct(false).must_equal manager
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'distinct_on' do
|
||||||
|
it 'sets the quantifier' do
|
||||||
|
manager = Arel::SelectManager.new Table.engine
|
||||||
|
table = Table.new :users
|
||||||
|
|
||||||
|
manager.distinct_on(table['id'])
|
||||||
|
manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table['id'])
|
||||||
|
|
||||||
|
manager.distinct_on(false)
|
||||||
|
manager.ast.cores.last.set_quantifier.must_equal nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "chains" do
|
||||||
|
manager = Arel::SelectManager.new Table.engine
|
||||||
|
table = Table.new :users
|
||||||
|
|
||||||
|
manager.distinct_on(table['id']).must_equal manager
|
||||||
|
manager.distinct_on(false).must_equal manager
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue