From e9c71a864bd33b3109e802efc7d03255037a899f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 12 Mar 2010 16:39:32 -0800 Subject: Support in memory ordering better. --- lib/arel/algebra/relations/operations/order.rb | 3 ++- lib/arel/algebra/relations/operations/where.rb | 12 ++---------- lib/arel/algebra/relations/utilities/compound.rb | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/arel/algebra/relations/operations/order.rb b/lib/arel/algebra/relations/operations/order.rb index a589b56997..df54735630 100644 --- a/lib/arel/algebra/relations/operations/order.rb +++ b/lib/arel/algebra/relations/operations/order.rb @@ -1,7 +1,8 @@ module Arel class Order < Compound attributes :relation, :orderings - deriving :== + deriving :== + requires :ordering def initialize(relation, *orderings, &block) @relation = relation diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb index 2fc51c7f24..6c9c5ed755 100644 --- a/lib/arel/algebra/relations/operations/where.rb +++ b/lib/arel/algebra/relations/operations/where.rb @@ -1,7 +1,8 @@ module Arel class Where < Compound attributes :relation, :predicate - deriving :== + deriving :== + requires :restricting def initialize(relation, *predicates, &block) predicate = block_given?? yield(relation) : predicates.shift @@ -9,15 +10,6 @@ module Arel @predicate = predicate.bind(@relation) end - def engine - # Temporary check of whether or not the engine supports where. - if relation.engine.respond_to?(:supports) && !relation.engine.supports(:where) - Memory::Engine.new - else - relation.engine - end - end - def wheres @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) } end diff --git a/lib/arel/algebra/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb index 1a43c76a94..882cf8a76b 100644 --- a/lib/arel/algebra/relations/utilities/compound.rb +++ b/lib/arel/algebra/relations/utilities/compound.rb @@ -5,6 +5,11 @@ module Arel :column_for, :engine, :sources, :locked, :table_alias, :to => :relation + def self.requires(feature = nil) + @requires = feature if feature + @requires + end + [:attributes, :wheres, :groupings, :orders, :havings, :projections].each do |operation_name| class_eval <<-OPERATION, __FILE__, __LINE__ def #{operation_name} @@ -21,6 +26,18 @@ module Arel self == other end + def engine + requires = self.class.requires + engine = relation.engine + + # Temporary check of whether or not the engine supports where. + if requires && engine.respond_to?(:supports) && !engine.supports(requires) + Memory::Engine.new + else + engine + end + end + private def arguments_from_block(relation, &block) -- cgit v1.2.3