Method: ROM::Factory::Attributes::Association::OneToMany#call

Defined in:
lib/rom/factory/attributes/association.rb

#call(attrs = EMPTY_HASH, parent, persist: true) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rom/factory/attributes/association.rb', line 99

def call(attrs = EMPTY_HASH, parent, persist: true)
  return if attrs.key?(name)

  structs = ::Array.new(count).map do
    # hash which contains the foreign key info, i.e: { user_id: 1 }
    association_hash = assoc.associate(attrs, parent)

    if persist
      builder.persistable.create(*traits, **association_hash)
    else
      builder.struct(*traits, **attrs, **association_hash)
    end
  end

  {name => structs}
end