diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/algebra/relations/operations/where.rb | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb index 3c5df117f6..e8db2ec8b0 100644 --- a/lib/arel/algebra/relations/operations/where.rb +++ b/lib/arel/algebra/relations/operations/where.rb @@ -1,18 +1,34 @@ module Arel class Where < Compound - attributes :relation, :predicates - deriving :== - requires :restricting + attr_reader :predicates def initialize(relation, *predicates) + super(relation) predicates = [yield(relation)] + predicates if block_given? @predicates = predicates.map { |p| p.bind(relation) } - @relation = relation @wheres = nil end def wheres @wheres ||= relation.wheres + predicates end + + def == other + super || + Where === other && + relation == other.relation && + predicates == other.predicates + end + + def engine + engine = relation.engine + + # Temporary check of whether or not the engine supports where. + if engine.respond_to?(:supports) && !engine.supports(:restricting) + Memory::Engine.new + else + engine + end + end end end |