From 496134516e19acd93772cfff8eafa4cb2dd8bc8d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 17:56:34 -0700 Subject: more unfactoring --- lib/arel/algebra/relations/operations/where.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib/arel/algebra') 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 -- cgit v1.2.3