Class: NinjaModel::Reflection::AssociationReflection
Instance Attribute Summary
#macro, #name, #ninja_model, #options
Instance Method Summary
collapse
#class_name, #klass
Constructor Details
#initialize(macro, name, options, ninja_model) ⇒ AssociationReflection
Returns a new instance of AssociationReflection.
55
56
57
58
|
# File 'lib/ninja_model/reflection.rb', line 55
def initialize(macro, name, options, ninja_model)
super
@collection = [:has_many].include?(macro)
end
|
Instance Method Details
#association_foreign_key ⇒ Object
76
77
78
|
# File 'lib/ninja_model/reflection.rb', line 76
def association_foreign_key
@association_foreign_key ||= @options[:association_foreign_key] || class_name.foreign_key
end
|
#build_association(*options) ⇒ Object
60
61
62
|
# File 'lib/ninja_model/reflection.rb', line 60
def build_association(*options)
klass.new(*options)
end
|
#collection? ⇒ Boolean
80
81
82
|
# File 'lib/ninja_model/reflection.rb', line 80
def collection?
@collection
end
|
#create_association(*options) ⇒ Object
64
65
66
|
# File 'lib/ninja_model/reflection.rb', line 64
def create_association(*options)
klass.create(*options)
end
|
#create_association!(*options) ⇒ Object
68
69
70
|
# File 'lib/ninja_model/reflection.rb', line 68
def create_association!(*options)
klass.create!(*options)
end
|
#primary_key_name ⇒ Object
72
73
74
|
# File 'lib/ninja_model/reflection.rb', line 72
def primary_key_name
@primary_key_name ||= options[:foreign_key] || derive_primary_key_name
end
|
#validate? ⇒ Boolean
84
85
86
|
# File 'lib/ninja_model/reflection.rb', line 84
def validate?
!options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many)
end
|