Skip to content

Commit

Permalink
Merge pull request #41579 from kamipo/tree_manager_takes_a_table
Browse files Browse the repository at this point in the history
Allow all tree managers' initializer takes a table
  • Loading branch information
kamipo committed Mar 2, 2021
2 parents 568ac22 + e27063a commit a8c462d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
Expand Up @@ -477,8 +477,7 @@ def build_fixture_sql(fixtures, table_name)
end

table = Arel::Table.new(table_name)
manager = Arel::InsertManager.new
manager.into(table)
manager = Arel::InsertManager.new(table)

if values_list.size == 1
values = values_list.shift
Expand Down
9 changes: 3 additions & 6 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -363,8 +363,7 @@ def _insert_record(values) # :nodoc:
end
end

im = Arel::InsertManager.new
im.into(arel_table)
im = Arel::InsertManager.new(arel_table)

if values.empty?
im.insert(connection.empty_insert_statement_value(primary_key))
Expand All @@ -386,8 +385,7 @@ def _update_record(values, constraints) # :nodoc:
constraints << current_scope.where_clause.ast
end

um = Arel::UpdateManager.new
um.table(arel_table)
um = Arel::UpdateManager.new(arel_table)
um.set(_substitute_values(values))
um.wheres = constraints

Expand All @@ -405,8 +403,7 @@ def _delete_record(constraints) # :nodoc:
constraints << current_scope.where_clause.ast
end

dm = Arel::DeleteManager.new
dm.from(arel_table)
dm = Arel::DeleteManager.new(arel_table)
dm.wheres = constraints

connection.delete(dm, "#{self} Destroy")
Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/arel/delete_manager.rb
Expand Up @@ -4,10 +4,11 @@ module Arel # :nodoc: all
class DeleteManager < Arel::TreeManager
include TreeManager::StatementMethods

def initialize
super
def initialize(table = nil)
super()
@ast = Nodes::DeleteStatement.new
@ctx = @ast
@ast.relation = table
end

def from(relation)
Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/arel/insert_manager.rb
Expand Up @@ -2,9 +2,10 @@

module Arel # :nodoc: all
class InsertManager < Arel::TreeManager
def initialize
super
def initialize(table = nil)
super()
@ast = Nodes::InsertStatement.new
@ast.relation = table
end

def into(table)
Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/arel/update_manager.rb
Expand Up @@ -4,10 +4,11 @@ module Arel # :nodoc: all
class UpdateManager < Arel::TreeManager
include TreeManager::StatementMethods

def initialize
super
def initialize(table = nil)
super()
@ast = Nodes::UpdateStatement.new
@ctx = @ast
@ast.relation = table
end

###
Expand Down

0 comments on commit a8c462d

Please sign in to comment.