Class: HecksAdapters::SQLDatabase::Commands::Create::AddToJoinTables

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/create/add_to_join_tables.rb

Overview

Update data in joining tables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head:, reference_ids:, id:) ⇒ AddToJoinTables

Returns a new instance of AddToJoinTables.



8
9
10
11
12
13
# 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

Instance Attribute Details

#reference_idsObject (readonly)

Returns the value of attribute reference_ids.



7
8
9
# File 'lib/commands/create/add_to_join_tables.rb', line 7

def reference_ids
  @reference_ids
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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