aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/nodes/select_core.rb10
-rw-r--r--lib/arel/nodes/unary.rb1
-rw-r--r--lib/arel/select_manager.rb4
-rw-r--r--lib/arel/visitors/depth_first.rb2
-rw-r--r--lib/arel/visitors/informix.rb7
-rw-r--r--lib/arel/visitors/to_sql.rb10
6 files changed, 18 insertions, 16 deletions
diff --git a/lib/arel/nodes/select_core.rb b/lib/arel/nodes/select_core.rb
index 09ae420aa1..3696dd20af 100644
--- a/lib/arel/nodes/select_core.rb
+++ b/lib/arel/nodes/select_core.rb
@@ -2,7 +2,7 @@ module Arel
module Nodes
class SelectCore < Arel::Nodes::Node
attr_accessor :top, :projections, :wheres, :groups, :windows
- attr_accessor :having, :source, :set_quantifier
+ attr_accessor :havings, :source, :set_quantifier
def initialize
super()
@@ -14,7 +14,7 @@ module Arel
@projections = []
@wheres = []
@groups = []
- @having = nil
+ @havings = []
@windows = []
end
@@ -35,14 +35,14 @@ module Arel
@projections = @projections.clone
@wheres = @wheres.clone
@groups = @groups.clone
- @having = @having.clone if @having
+ @havings = @havings.clone
@windows = @windows.clone
end
def hash
[
@source, @top, @set_quantifier, @projections,
- @wheres, @groups, @having, @windows
+ @wheres, @groups, @havings, @windows
].hash
end
@@ -54,7 +54,7 @@ module Arel
self.projections == other.projections &&
self.wheres == other.wheres &&
self.groups == other.groups &&
- self.having == other.having &&
+ self.havings == other.havings &&
self.windows == other.windows
end
alias :== :eql?
diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb
index 3d4a4b014a..a0062ff5be 100644
--- a/lib/arel/nodes/unary.rb
+++ b/lib/arel/nodes/unary.rb
@@ -23,7 +23,6 @@ module Arel
%w{
Bin
Group
- Having
Limit
Not
Offset
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index dd1ae37b65..e5fdbc887c 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -118,8 +118,8 @@ module Arel
join(relation, Nodes::OuterJoin)
end
- def having *exprs
- @ctx.having = Nodes::Having.new(collapse(exprs, @ctx.having))
+ def having expr
+ @ctx.havings << expr
self
end
diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb
index d7d85cfcc6..22704dd038 100644
--- a/lib/arel/visitors/depth_first.rb
+++ b/lib/arel/visitors/depth_first.rb
@@ -146,7 +146,7 @@ module Arel
visit o.wheres
visit o.groups
visit o.windows
- visit o.having
+ visit o.havings
end
def visit_Arel_Nodes_SelectStatement o
diff --git a/lib/arel/visitors/informix.rb b/lib/arel/visitors/informix.rb
index 7e8a3ea458..c33ef50554 100644
--- a/lib/arel/visitors/informix.rb
+++ b/lib/arel/visitors/informix.rb
@@ -34,8 +34,13 @@ module Arel
collector = inject_join o.groups, collector, ", "
end
- maybe_visit o.having, collector
+ if o.havings.any?
+ collector << " HAVING "
+ collector = inject_join o.havings, collector, " AND "
+ end
+ collector
end
+
def visit_Arel_Nodes_Offset o, collector
collector << "SKIP "
visit o.expr, collector
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index acf0a74d37..7dfa86a575 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -265,7 +265,10 @@ module Arel
end
end
- collector = maybe_visit o.having, collector
+ unless o.havings.empty?
+ collector << " HAVING "
+ inject_join o.havings, collector, AND
+ end
unless o.windows.empty?
collector << WINDOW
@@ -404,11 +407,6 @@ module Arel
end
end
- def visit_Arel_Nodes_Having o, collector
- collector << "HAVING "
- visit o.expr, collector
- end
-
def visit_Arel_Nodes_Offset o, collector
collector << "OFFSET "
visit o.expr, collector