Permalink
Browse files

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

… quantifier
  • Loading branch information...
1 parent 411336b commit c0396833cd826483f1b6c957d2b1a8f0b80056ec @jonleighton jonleighton committed Nov 4, 2011
Showing with 21 additions and 0 deletions.
  1. +8 −0 lib/arel/select_manager.rb
  2. +13 −0 test/test_select_manager.rb
@@ -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|
@@ -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.