aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/having.rb
blob: 0cd86c284e31bd96ef7d5f1ff0b8abfd58e674db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Arel
  class Having < Compound
    attributes :relation, :predicates
    deriving   :==
    requires   :restricting

    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