Module: MongoMapper::Plugins::Associations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document, EmbeddedDocument
- Defined in:
- lib/mongo_mapper.rb,
lib/mongo_mapper/plugins/associations.rb,
lib/mongo_mapper/plugins/associations/base.rb,
lib/mongo_mapper/plugins/associations/proxy.rb,
lib/mongo_mapper/plugins/associations/one_proxy.rb,
lib/mongo_mapper/plugins/associations/collection.rb,
lib/mongo_mapper/plugins/associations/one_as_proxy.rb,
lib/mongo_mapper/plugins/associations/in_array_proxy.rb,
lib/mongo_mapper/plugins/associations/one_association.rb,
lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb,
lib/mongo_mapper/plugins/associations/many_association.rb,
lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb,
lib/mongo_mapper/plugins/associations/single_association.rb,
lib/mongo_mapper/plugins/associations/embedded_collection.rb,
lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb,
lib/mongo_mapper/plugins/associations/many_documents_proxy.rb,
lib/mongo_mapper/plugins/associations/belongs_to_association.rb,
lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb,
lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb,
lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb,
lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb,
lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Base, BelongsToAssociation, BelongsToPolymorphicProxy, BelongsToProxy, Collection, EmbeddedCollection, InArrayProxy, ManyAssociation, ManyDocumentsAsProxy, ManyDocumentsProxy, ManyEmbeddedPolymorphicProxy, ManyEmbeddedProxy, ManyPolymorphicProxy, OneAsProxy, OneAssociation, OneEmbeddedPolymorphicProxy, OneEmbeddedProxy, OneProxy, Proxy, SingleAssociation
Instance Method Summary
collapse
Instance Method Details
#associations ⇒ Object
59
60
61
|
# File 'lib/mongo_mapper/plugins/associations.rb', line 59
def associations
self.class.associations
end
|
#build_proxy(association) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/mongo_mapper/plugins/associations.rb', line 67
def build_proxy(association)
proxy = association.proxy_class.new(self, association)
self.instance_variable_set(association.ivar, proxy)
proxy
end
|
#embedded_associations ⇒ Object
63
64
65
|
# File 'lib/mongo_mapper/plugins/associations.rb', line 63
def embedded_associations
associations.values.select { |assoc| assoc.embeddable? }
end
|
#get_proxy(association) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/mongo_mapper/plugins/associations.rb', line 74
def get_proxy(association)
unless proxy = self.instance_variable_get(association.ivar)
proxy = build_proxy(association)
end
proxy
end
|
#save_to_collection(options = {}) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/mongo_mapper/plugins/associations.rb', line 81
def save_to_collection(options={})
super if defined?(super)
associations.each do |association_name, association|
proxy = get_proxy(association)
proxy.save_to_collection(options) if proxy.proxy_respond_to?(:save_to_collection) && association.autosave?
end
end
|