Permalink
Browse files

Support in memory ordering better.

  • Loading branch information...
1 parent 3ab6ae0 commit e9c71a864bd33b3109e802efc7d03255037a899f Carl Lerche committed Mar 13, 2010
@@ -1,7 +1,8 @@
module Arel
class Order < Compound
attributes :relation, :orderings
- deriving :==
+ deriving :==
+ requires :ordering
def initialize(relation, *orderings, &block)
@relation = relation
@@ -1,23 +1,15 @@
module Arel
class Where < Compound
attributes :relation, :predicate
- deriving :==
+ deriving :==
+ requires :restricting
def initialize(relation, *predicates, &block)
predicate = block_given?? yield(relation) : predicates.shift
@relation = predicates.empty?? relation : Where.new(relation, *predicates)
@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
@@ -5,6 +5,11 @@ class Compound < Relation
: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 @@ def eql?(other)
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)

0 comments on commit e9c71a8

Please sign in to comment.