Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@samuelkadolph

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

@tenderlove tenderlove merged commit 5930020 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2011
  1. @samuelkadolph
This page is out of date. Refresh to see the latest.
View
1  lib/arel/nodes/function.rb
@@ -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
View
2  lib/arel/nodes/named_function.rb
@@ -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
View
9 test/nodes/test_count.rb
@@ -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.