Class: ActiveData::Model::Associations::Reflections::ReferencesOne

Inherits:
ReferencesAny
  • Object
show all
Includes:
Singular
Defined in:
lib/active_data/model/associations/reflections/references_one.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 included from Singular

#collection?

Methods inherited from ReferencesAny

#autosave?, #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 ActiveData::Model::Associations::Reflections::ReferencesAny

Class Method Details

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



11
12
13
14
15
16
17
18
19
20
# File 'lib/active_data/model/associations/reflections/references_one.rb', line 11

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

  target.add_attribute(
    ActiveData::Model::Attributes::Reflections::ReferenceOne,
    reflection.reference_key, association: name
  )

  reflection
end

Instance Method Details

#reference_keyObject



22
23
24
25
# File 'lib/active_data/model/associations/reflections/references_one.rb', line 22

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