diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-03 15:53:22 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-03 15:53:22 -0800 |
commit | 02eaa7ee6ea812e61681912719d3875401eeabe3 (patch) | |
tree | 1fac7fa9cf85a059f78bca38fa4c68d040317ff0 /lib/arel | |
parent | b08e994d471304baec7b04ad2824230c151ca3f5 (diff) | |
parent | 8bc0fce00b9f64e328c18e98f82780e29dc5f554 (diff) | |
download | rails-02eaa7ee6ea812e61681912719d3875401eeabe3.tar.gz rails-02eaa7ee6ea812e61681912719d3875401eeabe3.tar.bz2 rails-02eaa7ee6ea812e61681912719d3875401eeabe3.zip |
Merge branch 'master' of github.com:rails/arel
* 'master' of github.com:rails/arel:
Allow HAVING to take multiple conditions, like WHERE
Diffstat (limited to 'lib/arel')
-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 |