Module: MongoMapper::Plugins::Associations::InstanceMethods

Defined in:
lib/mongo_mapper/plugins/associations.rb

Instance Method Summary collapse

Instance Method Details

#associationsObject



98
99
100
# File 'lib/mongo_mapper/plugins/associations.rb', line 98

def associations
  self.class.associations
end

#build_proxy(association) ⇒ Object



110
111
112
113
114
115
# File 'lib/mongo_mapper/plugins/associations.rb', line 110

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

  proxy
end

#embedded_associationsObject



102
103
104
105
106
107
108
# File 'lib/mongo_mapper/plugins/associations.rb', line 102

def embedded_associations
  associations.select do |name, association|
    association.embeddable?
  end.map do |name, association|
    association
  end
end

#get_proxy(association) ⇒ Object



117
118
119
120
121
122
# File 'lib/mongo_mapper/plugins/associations.rb', line 117

def get_proxy(association)
  unless proxy = self.instance_variable_get(association.ivar)
    proxy = build_proxy(association)
  end
  proxy
end

#save_to_collection(options = {}) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/mongo_mapper/plugins/associations.rb', line 124

def save_to_collection(options={})
  super
  associations.each do |association_name, association|
    proxy = get_proxy(association)
    proxy.save_to_collection(options) if proxy.proxy_respond_to?(:save_to_collection)
  end
end