Module: Mongoid::Associations::InstanceMethods

Defined in:
lib/mongoid/associations.rb

Instance Method Summary collapse

Instance Method Details

#associationsObject

Returns the associations for the Document.



27
28
29
# File 'lib/mongoid/associations.rb', line 27

def associations
  self.class.associations
end

#embedded_many?Boolean

are we in an embeds_many?

Returns:



32
33
34
# File 'lib/mongoid/associations.rb', line 32

def embedded_many?
  embedded? and _parent.associations[association_name].association == EmbedsMany
end

#update_association(name) ⇒ Object

Update the one-to-one relational association for the name.



43
44
45
46
# File 'lib/mongoid/associations.rb', line 43

def update_association(name)
  association = send(name)
  association.save if new_record? && !association.nil?
end

#update_associations(name) ⇒ Object

Updates all the one-to-many relational associations for the name.



49
50
51
# File 'lib/mongoid/associations.rb', line 49

def update_associations(name)
  send(name).each { |doc| doc.save } if new_record?
end

#update_embedded(name) ⇒ Object

Update all the dirty child documents after an update.



37
38
39
40
# File 'lib/mongoid/associations.rb', line 37

def update_embedded(name)
  association = send(name)
  association.to_a.each { |doc| doc.save if doc.changed? || doc.new_record? } unless association.blank?
end