diff options
author | Ernie Miller <ernie@metautonomo.us> | 2010-05-21 11:45:12 -0400 |
---|---|---|
committer | Ernie Miller <ernie@metautonomo.us> | 2010-05-21 11:45:12 -0400 |
commit | 43bfd3fae496a2a859aad0a654a91437357c3450 (patch) | |
tree | bd95f3b7add4ba7841a6fa9dd717de9c60ea90a8 /lib/arel/algebra | |
parent | d144b8d5af11c819b8f70a97006998bf89ee926c (diff) | |
download | rails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.gz rails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.bz2 rails-43bfd3fae496a2a859aad0a654a91437357c3450.zip |
Fix tests to work properly on Ruby 1.9, honor multiple calls to #order in memory engine, and make having clauses behave like where clauses in SQL engine (join with AND, allow multiple calls to having to add predicates)
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r-- | lib/arel/algebra/relations/operations/having.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/arel/algebra/relations/operations/having.rb b/lib/arel/algebra/relations/operations/having.rb index cd16535609..0cd86c284e 100644 --- a/lib/arel/algebra/relations/operations/having.rb +++ b/lib/arel/algebra/relations/operations/having.rb @@ -1,13 +1,17 @@ module Arel class Having < Compound - attributes :relation, :havings - deriving :== + attributes :relation, :predicates + deriving :== + requires :restricting - def initialize(relation, *havings, &block) - @relation = relation - @havings = (havings + arguments_from_block(relation, &block)) \ - .collect { |g| g.bind(relation) } + def initialize(relation, *predicates, &block) + predicates = [yield(relation)] + predicates if block_given? + @predicates = predicates.map { |p| p.bind(relation) } + @relation = relation + end + + def havings + @havings ||= relation.havings + predicates end end end - |