Class: ROM::Factory::Attributes::Association::OneToOne Private
- 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.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rom/factory/attributes/association.rb', line 123 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 = ::ROM::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 |