Class: HecksAdapters::SQLDatabase::Commands::Create::AddToJoinTables
- Inherits:
-
Object
- Object
- HecksAdapters::SQLDatabase::Commands::Create::AddToJoinTables
- Defined in:
- lib/commands/create/add_to_join_tables.rb
Overview
Update data in joining tables
Instance Attribute Summary collapse
-
#reference_ids ⇒ Object
readonly
Returns the value of attribute reference_ids.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(head:, reference_ids:, id:) ⇒ AddToJoinTables
constructor
A new instance of AddToJoinTables.
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_ids ⇒ Object (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
#call ⇒ Object
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 |