diff options
author | Carl Lerche <carllerche@mac.com> | 2010-03-12 16:39:32 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-03-12 16:39:32 -0800 |
commit | e9c71a864bd33b3109e802efc7d03255037a899f (patch) | |
tree | a4120f0f2be359bbf4a78688e02dd89c0503a643 | |
parent | 3ab6ae0c601d1b4459efd8bb39650fee370aa5b8 (diff) | |
download | rails-e9c71a864bd33b3109e802efc7d03255037a899f.tar.gz rails-e9c71a864bd33b3109e802efc7d03255037a899f.tar.bz2 rails-e9c71a864bd33b3109e802efc7d03255037a899f.zip |
Support in memory ordering better.
-rw-r--r-- | lib/arel/algebra/relations/operations/order.rb | 3 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/where.rb | 12 | ||||
-rw-r--r-- | lib/arel/algebra/relations/utilities/compound.rb | 17 |
3 files changed, 21 insertions, 11 deletions
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) |