class HecksAdapters::SQLDatabase::Commands::Update::LinkToReferences

Link to any new references

Attributes

reference_ids[R]

Public Class Methods

new(reference:, table:, reference_ids:, attributes:, id:) click to toggle source
# File lib/commands/update/link_to_references.rb, line 8
def initialize(reference:, table:, reference_ids:, attributes:, id:)
  @reference = reference
  @reference_ids = reference_ids
  @table = table
  @attributes = attributes
  @column = Column.factory(@reference)
  @record = {}
  @id = id
end

Public Instance Methods

call() click to toggle source
# File lib/commands/update/link_to_references.rb, line 18
def call
  make_linking_records
  make_foreign_keys
  self
end

Private Instance Methods

make_foreign_keys() click to toggle source
# File lib/commands/update/link_to_references.rb, line 36
def make_foreign_keys
  return if @reference.list?
  @attributes[@column.to_foreign_key] = @reference_ids[@reference.name]
end
make_linking_records() click to toggle source
# File lib/commands/update/link_to_references.rb, line 26
def make_linking_records

  return unless @reference.list?
  @reference_ids[@reference.name.to_sym].each do |value|
    @record[@column.to_foreign_key] = value
    @record[@table.to_foreign_key] = @id
    DB[JoinTable.new(@table, @reference).name.to_sym].insert(@record.merge(id: SecureRandom.uuid))
  end
end