Class: Granite::Form::Model::Associations::Reflections::ReferencesMany

Inherits:
ReferencesAny
  • Object
show all
Defined in:
lib/granite/form/model/associations/reflections/references_many.rb

Constant Summary

Constants inherited from Base

Base::READ, Base::WRITE

Instance Attribute Summary

Attributes inherited from Base

#name, #options, #parent_reflection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ReferencesAny

#embedded?, #initialize, #inspect, #klass, #persistence_adapter, persistence_adapter, #read_source, #write_source

Methods inherited from Base

association_class, #belongs_to?, #build_association, #collection?, #default, generate_methods, #initialize, #klass, #macro, #read_source, #write_source

Constructor Details

This class inherits a constructor from Granite::Form::Model::Associations::Reflections::ReferencesAny

Class Method Details

.build(target, generated_methods, name, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/granite/form/model/associations/reflections/references_many.rb', line 10

def self.build(target, generated_methods, name, *args, &block)
  reflection = super

  target.add_attribute(
    Granite::Form::Model::Attributes::Reflections::ReferenceMany,
    reflection.reference_key,
    type: reflection.persistence_adapter.primary_key_type,
    association: name
  )

  reflection
end

Instance Method Details

#reference_keyObject



23
24
25
26
# File 'lib/granite/form/model/associations/reflections/references_many.rb', line 23

def reference_key
  @reference_key ||= options[:reference_key].presence.try(:to_sym) ||
                     :"#{name.to_s.singularize}_#{primary_key.to_s.pluralize}"
end