Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for distinct_on #179

Closed
wants to merge 1 commit into from

7 participants

@beedub

No description provided.

@zzet

:+1: nice!

@prathamesh-sonpatki

Any update on this?

@mrgordon

Any update?

@tamird

good to close, was added in 112cb94

@matthewd matthewd closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 12, 2013
  1. @beedub

    add support for distinct_on

    beedub authored
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +7 −0 lib/arel/select_manager.rb
  2. +14 −0 test/test_select_manager.rb
View
7 lib/arel/select_manager.rb
@@ -153,6 +153,13 @@ def distinct(value = true)
end
end
+ def distinct_on(value = nil)
+ @ctx.set_quantifier = if value
+ Arel::Nodes::DistinctOn.new(value)
+ end
+ self
+ end
+
def order *expr
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@ast.orders.concat expr.map { |x|
View
14 test/test_select_manager.rb
@@ -1150,5 +1150,19 @@ def test_join_sources
manager.ast.cores.last.set_quantifier.must_equal nil
end
end
+
+ describe "distinct_on" do
+ it "sets the quantifier" do
+ manager = Arel::SelectManager.new Table.engine
+
+ manager.distinct_on("id")
+ quantifier = manager.ast.cores.last.set_quantifier
+ quantifier.class.must_equal Arel::Nodes::DistinctOn
+ quantifier.expr.must_equal "id"
+
+ manager.distinct(false)
+ manager.ast.cores.last.set_quantifier.must_equal nil
+ end
+ end
end
end
Something went wrong with that request. Please try again.