1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

refactoring where, fixing subselect

This commit is contained in:
Aaron Patterson 2010-12-07 10:46:30 -08:00
parent 16ee8f66bc
commit 4147f4bbf8
6 changed files with 13 additions and 16 deletions

View file

@ -3,6 +3,7 @@ module Arel
def initialize engine
super
@ast = Nodes::DeleteStatement.new
@ctx = @ast
end
def from relation
@ -10,11 +11,6 @@ module Arel
self
end
def where expression
@ast.wheres << expression
self
end
def wheres= list
@ast.wheres = list
end

View file

@ -31,7 +31,7 @@ module Arel
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 @@ module Arel
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 file

@ -107,11 +107,6 @@ module Arel
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 file

@ -9,6 +9,7 @@ module Arel
def initialize engine
@engine = engine
@visitor = Visitors.visitor_for @engine
@ctx = nil
end
def to_dot
@ -23,5 +24,13 @@ module Arel
super
@ast = @ast.clone
end
def where expr
if Arel::TreeManager === expr
expr = expr.ast
end
@ctx.wheres << expr
self
end
end
end

View file

@ -3,6 +3,7 @@ module Arel
def initialize engine
super
@ast = Nodes::UpdateStatement.new
@ctx = @ast
end
def take limit

View file

@ -72,10 +72,6 @@ module Arel
}.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,