Class: MongoMapper::Plugins::Associations::OneAssociation
Constant Summary
Constants inherited
from Base
Base::AssociationOptions
Instance Attribute Summary
Attributes inherited from Base
#name, #options, #query_options
Instance Method Summary
collapse
Methods inherited from Base
#as, #as?, #class_name, #foreign_key, #in_array?, #initialize, #ivar, #klass, #polymorphic?, #touch?, #type_key_name
Instance Method Details
42
43
44
|
# File 'lib/mongo_mapper/plugins/associations/one_association.rb', line 42
def autosave?
options.fetch(:autosave, embeddable?)
end
|
#embeddable? ⇒ Boolean
6
7
8
|
# File 'lib/mongo_mapper/plugins/associations/one_association.rb', line 6
def embeddable?
klass.embeddable?
end
|
#setup(model) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mongo_mapper/plugins/associations/one_association.rb', line 21
def setup(model)
super
association = self
options = self.options
model.before_destroy do
if !association.embeddable?
proxy = self.get_proxy(association)
unless proxy.nil?
case options[:dependent]
when :destroy then proxy.destroy
when :delete then proxy.delete
else proxy.nullify
end
end
end
end
end
|