Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Include Arel::Predicates to Arel::Nodes::Function #55

Merged
merged 1 commit into from

2 participants

Samuel Kadolph Aaron Patterson
Samuel Kadolph

This lets you do table[:id].count.eq(2).
Useful for when you GROUP BY and want to add HAVING COUNT("things"."id") = 2.

Aaron Patterson tenderlove merged commit 5930020 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2011
  1. Samuel Kadolph
This page is out of date. Refresh to see the latest.
1  lib/arel/nodes/function.rb
View
@@ -2,6 +2,7 @@ module Arel
module Nodes
class Function < Arel::Nodes::Node
include Arel::Expression
+ include Arel::Predications
attr_accessor :expressions, :alias, :distinct
def initialize expr, aliaz = nil
2  lib/arel/nodes/named_function.rb
View
@@ -3,8 +3,6 @@ module Nodes
class NamedFunction < Arel::Nodes::Function
attr_accessor :name
- include Arel::Predications
-
def initialize name, expr, aliaz = nil
super(expr, aliaz)
@name = name
9 test/nodes/test_count.rb
View
@@ -15,4 +15,13 @@
}
end
end
+
+ describe "eq" do
+ it "should compare the count" do
+ table = Arel::Table.new :users
+ table[:id].count.eq(2).to_sql.must_be_like %{
+ COUNT("users"."id") = 2
+ }
+ end
+ end
end
Something went wrong with that request. Please try again.