Class: Seedie::Associations::BelongsTo

Inherits:
BaseAssociation show all
Defined in:
lib/seedie/associations/belongs_to.rb

Constant Summary

Constants inherited from BaseAssociation

Seedie::Associations::BaseAssociation::DEFAULT_COUNT, Seedie::Associations::BaseAssociation::INDEX

Instance Attribute Summary collapse

Attributes inherited from BaseAssociation

#association_config, #model, #record, #reporters

Instance Method Summary collapse

Methods included from Reporters::Reportable

#add_observers, #report

Constructor Details

#initialize(model, association_config, reporters = []) ⇒ BelongsTo

Returns a new instance of BelongsTo.



8
9
10
11
12
# File 'lib/seedie/associations/belongs_to.rb', line 8

def initialize(model, association_config, reporters = [])
  super(nil, model, association_config, reporters)

  @associated_field_set = {}
end

Instance Attribute Details

#associated_field_setObject (readonly)

Returns the value of attribute associated_field_set.



6
7
8
# File 'lib/seedie/associations/belongs_to.rb', line 6

def associated_field_set
  @associated_field_set
end

Instance Method Details

#generate_association(klass, config, index) ⇒ Object



26
27
28
29
30
# File 'lib/seedie/associations/belongs_to.rb', line 26

def generate_association(klass, config, index)
  field_values_set = FieldValuesSet.new(klass, config, index).generate_field_values

  Model::Creator.new(klass).create!(field_values_set)
end

#generate_associationsObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/seedie/associations/belongs_to.rb', line 14

def generate_associations
  return if association_config["belongs_to"].nil?

  report(:belongs_to_start)

  association_config["belongs_to"].each do |association_name, association_config|
    reflection = model.reflect_on_association(association_name)

    handle_association_config_type(reflection, association_name, association_config)
  end
end