aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/operations/where.rb
blob: ba34846c041b3b8c905ee289a3e592288a6665f8 (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 Where < Compound
    attr_reader :predicate

    def initialize(relation, *predicates)
      predicate = predicates.shift
      @relation = predicates.empty?? relation : Where.new(relation, *predicates)
      @predicate = predicate.bind(@relation)
    end

    def wheres
      @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) }
    end    

    def ==(other)
      Where     === other          and
      relation  ==  other.relation and
      predicate ==  other.predicate
    end
  end
end