Class: ActiveFedora::Reflection::ClassMethods::AssociationReflection

Inherits:
MacroReflection
  • Object
show all
Defined in:
lib/active_fedora/reflection.rb

Overview

Holds all the meta-data about an association as it was specified in the Active Record class.

Instance Attribute Summary

Attributes inherited from MacroReflection

#macro, #name, #options

Instance Method Summary collapse

Methods inherited from MacroReflection

#build_association, #class_name, #collection?, #klass

Constructor Details

#initialize(macro, name, options, active_record) ⇒ AssociationReflection

:nodoc:



114
115
116
117
# File 'lib/active_fedora/reflection.rb', line 114

def initialize(macro, name, options, active_record)
  super
  @collection = [:has_many, :has_and_belongs_to_many].include?(macro)
end

Instance Method Details

#create_association(*options) ⇒ Object

Creates a new instance of the associated class, and immediately saves it with ActiveRecord::Base#save. options will be passed to the class’s creation method. Returns the newly created object.



126
127
128
# File 'lib/active_fedora/reflection.rb', line 126

def create_association(*options)
  klass.create(*options)
end

#primary_key_nameObject



119
120
121
# File 'lib/active_fedora/reflection.rb', line 119

def primary_key_name
  @primary_key_name ||= options[:foreign_key] || derive_primary_key_name
end