diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-04 07:11:34 +0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-04 07:19:58 +0800 |
commit | 8bc0fce00b9f64e328c18e98f82780e29dc5f554 (patch) | |
tree | 791d2d112adb4d21c5e8d1a333b55eb39de0be6a /lib | |
parent | 597fe1580902f9ae661992448c966bc6372d5ba0 (diff) | |
download | rails-8bc0fce00b9f64e328c18e98f82780e29dc5f554.tar.gz rails-8bc0fce00b9f64e328c18e98f82780e29dc5f554.tar.bz2 rails-8bc0fce00b9f64e328c18e98f82780e29dc5f554.zip |
Allow HAVING to take multiple conditions, like WHERE
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/select_manager.rb | 20 |
1 files changed, 12 insertions, 8 deletions
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 |