From aac9da257f291ad8d2d4f914528881c240848bb2 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 27 Jan 2015 09:52:54 -0700 Subject: Change the interface of `having` to match that of `where` These two clauses have nearly identical semantics with regards to how they would be constructed as an AST. It doesn't make sense for their interfaces to be separate. --- lib/arel/visitors/depth_first.rb | 2 +- lib/arel/visitors/informix.rb | 7 ++++++- lib/arel/visitors/to_sql.rb | 10 ++++------ 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/arel/visitors') 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 -- cgit v1.2.3