Move `where` from `TreeManager` to `SelectManager`

`TreeManager` is inherited by `InsertManager` but `where` on
`InsertManager` doesn't work.

And also, remove `@ctx` since the instance variable is used only for the
`SelectManager`.
This commit is contained in:
Ryuta Kamizono 2021-03-15 23:50:44 +09:00
parent 92281b4911
commit 096719ce2a
5 changed files with 8 additions and 18 deletions

View File

@ -5,9 +5,7 @@ module Arel # :nodoc: all
include TreeManager::StatementMethods
def initialize(table = nil)
super()
@ast = Nodes::DeleteStatement.new(table)
@ctx = @ast
end
def from(relation)

View File

@ -3,7 +3,6 @@
module Arel # :nodoc: all
class InsertManager < Arel::TreeManager
def initialize(table = nil)
super()
@ast = Nodes::InsertStatement.new(table)
end

View File

@ -7,7 +7,6 @@ module Arel # :nodoc: all
STRING_OR_SYMBOL_CLASS = [Symbol, String]
def initialize(table = nil)
super()
@ast = Nodes::SelectStatement.new(table)
@ctx = @ast.cores.last
end
@ -182,6 +181,14 @@ module Arel # :nodoc: all
@ast.orders
end
def where(expr)
if Arel::TreeManager === expr
expr = expr.ast
end
@ctx.wheres << expr
self
end
def where_sql(engine = Table.engine)
return if @ctx.wheres.empty?

View File

@ -40,10 +40,6 @@ module Arel # :nodoc: all
attr_reader :ast
def initialize
@ctx = nil
end
def to_dot
collector = Arel::Collectors::PlainString.new
collector = Visitors::Dot.new.accept @ast, collector
@ -60,13 +56,5 @@ module Arel # :nodoc: all
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

@ -5,9 +5,7 @@ module Arel # :nodoc: all
include TreeManager::StatementMethods
def initialize(table = nil)
super()
@ast = Nodes::UpdateStatement.new(table)
@ctx = @ast
end
###