class HecksAdapters::SQLDatabase::Commands::Create::AddToJoinTables
Update
data in joining tables
Attributes
reference_ids[R]
Public Class Methods
new(head:, reference_ids:, id:)
click to toggle source
# File lib/commands/create/add_to_join_tables.rb, line 8 def initialize(head:, reference_ids:, id:) @head = head @table = Table.factory([@head]).first @reference_ids = reference_ids @id = id end
Public Instance Methods
call()
click to toggle source
# File lib/commands/create/add_to_join_tables.rb, line 15 def call @head.references.each do |reference| column = Column.factory(reference) join_table = JoinTable.new(@table, column) next unless reference.list? @reference_ids[reference.name.downcase].each do |id| DB[join_table.name.to_sym].insert(record(column, id).merge(id: SecureRandom.uuid)) end end self end
Private Instance Methods
record(column, id)
click to toggle source
# File lib/commands/create/add_to_join_tables.rb, line 32 def record(column, id) [[@table.to_foreign_key, @id], [(column.to_foreign_key).to_sym, id]].to_h end