Module: MarkMapper::Plugins::Associations

Extended by:
ActiveSupport::Concern
Included in:
Document, EmbeddedDocument
Defined in:
lib/mark_mapper.rb,
lib/mark_mapper/plugins/associations.rb,
lib/mark_mapper/plugins/associations/base.rb,
lib/mark_mapper/plugins/associations/proxy.rb,
lib/mark_mapper/plugins/associations/one_proxy.rb,
lib/mark_mapper/plugins/associations/collection.rb,
lib/mark_mapper/plugins/associations/one_as_proxy.rb,
lib/mark_mapper/plugins/associations/in_array_proxy.rb,
lib/mark_mapper/plugins/associations/one_association.rb,
lib/mark_mapper/plugins/associations/belongs_to_proxy.rb,
lib/mark_mapper/plugins/associations/many_association.rb,
lib/mark_mapper/plugins/associations/one_embedded_proxy.rb,
lib/mark_mapper/plugins/associations/single_association.rb,
lib/mark_mapper/plugins/associations/embedded_collection.rb,
lib/mark_mapper/plugins/associations/many_embedded_proxy.rb,
lib/mark_mapper/plugins/associations/many_documents_proxy.rb,
lib/mark_mapper/plugins/associations/many_polymorphic_proxy.rb,
lib/mark_mapper/plugins/associations/belongs_to_association.rb,
lib/mark_mapper/plugins/associations/many_documents_as_proxy.rb,
lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb,
lib/mark_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb,
lib/mark_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

#associationsObject


67
68
69
# File 'lib/mark_mapper/plugins/associations.rb', line 67

def associations
  self.class.associations
end

#build_proxy(association) ⇒ Object


75
76
77
78
79
80
# File 'lib/mark_mapper/plugins/associations.rb', line 75

def build_proxy(association)
  proxy = association.proxy_class.new(self, association)
  self.instance_variable_set(association.ivar, proxy)

  proxy
end

#embedded_associationsObject


71
72
73
# File 'lib/mark_mapper/plugins/associations.rb', line 71

def embedded_associations
  self.class.embedded_associations
end

#get_proxy(association) ⇒ Object


82
83
84
85
# File 'lib/mark_mapper/plugins/associations.rb', line 82

def get_proxy(association)
  proxy = self.instance_variable_get(association.ivar) if instance_variable_defined?(association.ivar)
  proxy ||= build_proxy(association)
end

#save_to_collection(options = {}) ⇒ Object


87
88
89
90
91
92
93
# File 'lib/mark_mapper/plugins/associations.rb', line 87

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