Skip to content
Browse files

refactoring where, fixing subselect

  • Loading branch information...
1 parent 16ee8f6 commit 4147f4bbf8c47379e795acfe0b65d6260e23a197 @tenderlove tenderlove committed
View
6 lib/arel/delete_manager.rb
@@ -3,6 +3,7 @@ class DeleteManager < Arel::TreeManager
def initialize engine
super
@ast = Nodes::DeleteStatement.new
+ @ctx = @ast
end
def from relation
@@ -10,11 +11,6 @@ def from relation
self
end
- def where expression
- @ast.wheres << expression
- self
- end
-
def wheres= list
@ast.wheres = list
end
View
4 lib/arel/predications.rb
@@ -31,7 +31,7 @@ def eq_all others
def in other
case other
when Arel::SelectManager
- Arel::Nodes::In.new(self, other)
+ Arel::Nodes::In.new(self, other.ast)
when Range
if other.exclude_end?
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
@@ -56,7 +56,7 @@ def in_all others
def not_in other
case other
when Arel::SelectManager
- Arel::Nodes::NotIn.new(self, other)
+ Arel::Nodes::NotIn.new(self, other.ast)
when Range
if other.exclude_end?
left = Nodes::LessThan.new(self, other.begin)
View
5 lib/arel/select_manager.rb
@@ -107,11 +107,6 @@ def project *projections
self
end
- def where expr
- @ctx.wheres << expr
- self
- end
-
def order *expr
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@ast.orders.concat expr.map { |x|
View
9 lib/arel/tree_manager.rb
@@ -9,6 +9,7 @@ class TreeManager
def initialize engine
@engine = engine
@visitor = Visitors.visitor_for @engine
+ @ctx = nil
end
def to_dot
@@ -23,5 +24,13 @@ def initialize_copy other
super
@ast = @ast.clone
end
+
+ def where expr
+ if Arel::TreeManager === expr
+ expr = expr.ast
+ end
+ @ctx.wheres << expr
+ self
+ end
end
end
View
1 lib/arel/update_manager.rb
@@ -3,6 +3,7 @@ class UpdateManager < Arel::TreeManager
def initialize engine
super
@ast = Nodes::UpdateStatement.new
+ @ctx = @ast
end
def take limit
View
4 lib/arel/visitors/to_sql.rb
@@ -72,10 +72,6 @@ def visit_Arel_Nodes_Values o
}.join ', '})"
end
- def visit_Arel_SelectManager o
- o.to_sql
- end
-
def visit_Arel_Nodes_SelectStatement o
[
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,

0 comments on commit 4147f4b

Please sign in to comment.
Something went wrong with that request. Please try again.