From 8bc0fce00b9f64e328c18e98f82780e29dc5f554 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 4 Jan 2011 07:11:34 +0800 Subject: Allow HAVING to take multiple conditions, like WHERE --- lib/arel/select_manager.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 3e0d4038d7..b4103144fe 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -97,10 +97,8 @@ module Arel self end - def having expr - expr = Nodes::SqlLiteral.new(expr) if String === expr - - @ctx.having = Nodes::Having.new(expr) + def having *exprs + @ctx.having = Nodes::Having.new(collapse(exprs, @ctx.having)) self end @@ -211,16 +209,22 @@ switch to `compile_insert` end private - def collapse exprs - return exprs.first if exprs.length == 1 - - create_and exprs.compact.map { |expr| + def collapse exprs, existing = nil + exprs = exprs.unshift(existing.expr) if existing + exprs = exprs.compact.map { |expr| if String === expr + # FIXME: Don't do this automatically Arel.sql(expr) else expr end } + + if exprs.length == 1 + exprs.first + else + create_and exprs + end end end end -- cgit v1.2.3