aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/having.rb
blob: fdd35626af43c227ba6908c32f74ce261f2923e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Arel
  class Having < Compound
    attr_reader :predicates

    def initialize(relation, *predicates)
      super(relation)
      predicates = [yield(relation)] + predicates if block_given?
      @predicates = predicates.map { |p| p.bind(relation) }
    end

    def havings
      @havings ||= relation.havings + predicates
    end

    def == other
      super || Having === other &&
               relation == other.relation &&
               predicates == other.predicates
    end
  end
end