aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/select_manager.rb8
-rw-r--r--test/test_select_manager.rb13
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 7a1fbbe438..ce8a9caf23 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -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|
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index a00d1843ba..bd5a4be68b 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -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