Skip to content

Commit

Permalink
Add SelectManager#distinct to set/unset the Arel::Nodes::Distinct.new…
Browse files Browse the repository at this point in the history
… quantifier
  • Loading branch information
jonleighton committed Nov 4, 2011
1 parent 411336b commit c039683
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/arel/select_manager.rb
Expand Up @@ -139,6 +139,14 @@ def projections= projections
@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|
Expand Down
13 changes: 13 additions & 0 deletions test/test_select_manager.rb
Expand Up @@ -981,5 +981,18 @@ def test_join_sources
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

0 comments on commit c039683

Please sign in to comment.