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

Add SelectManager#distinct to set/unset the Arel::Nodes::Distinct.new quantifier

This commit is contained in:
Jon Leighton 2011-11-04 16:55:40 +00:00
parent 411336b867
commit c0396833cd
2 changed files with 21 additions and 0 deletions

View file

@ -139,6 +139,14 @@ module Arel
@ctx.projections = projections
end
def distinct(value = true)
if value
@ctx.set_quantifier = Arel::Nodes::Distinct.new
else
@ctx.set_quantifier = nil
end
end
def order *expr
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@ast.orders.concat expr.map { |x|

View file

@ -981,5 +981,18 @@ module Arel
manager.source.must_equal manager.ast.cores.last.source
end
end
describe 'distinct' do
it 'sets the quantifier' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.distinct
manager.ast.cores.last.set_quantifier.class.must_equal Arel::Nodes::Distinct
manager.distinct(false)
manager.ast.cores.last.set_quantifier.must_equal nil
end
end
end
end