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, opts) ⇒ 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rom/factory/attributes/association.rb', line 101 def call(attrs = EMPTY_HASH, parent, opts) return if attrs.key?(name) association_hash = assoc.associate(attrs, parent) struct = if opts.fetch(:persist, true) 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 |