Class: ROM::Factory::Attributes::Association::OneToOne Private

Inherits:
OneToMany
  • Object
show all
Defined in:
lib/rom/factory/attributes/association.rb

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

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from ROM::Factory::Attributes::Association::Core

Instance Method Details

#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.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rom/factory/attributes/association.rb', line 138

def call(attrs = EMPTY_HASH, parent, persist: true)
  # do not associate if count is 0
  return {name => nil} if count.zero?

  return if attrs.key?(name)

  association_hash = assoc.associate(attrs, parent)

  struct = if persist
             builder.persistable.create(*traits, **association_hash)
           else
             belongs_to_name = Dry::Core::Inflector.singularize(assoc.source_alias)
             belongs_to_associations = {belongs_to_name.to_sym => parent}
             final_attrs = attrs.merge(association_hash).merge(belongs_to_associations)
             builder.struct(*traits, **final_attrs)
           end

  {name => struct}
end