diff options
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 - |