class ROM::Factory::Attributes::Association::OneToOne

@api private

Public Instance Methods

call(attrs = EMPTY_HASH, parent, persist: true) click to toggle source

@api private

# File lib/rom/factory/attributes/association.rb, line 104
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
count() click to toggle source

@api private

# File lib/rom/factory/attributes/association.rb, line 125
def count
  options.fetch(:count, 1)
end