Module: Mongoid::Associations::InstanceMethods
- Defined in:
- lib/mongoid/associations.rb
Instance Method Summary collapse
-
#associations ⇒ Object
Returns the associations for the
Document
. -
#embedded_many? ⇒ Boolean
are we in an embeds_many?.
-
#update_association(name) ⇒ Object
Update the one-to-one relational association for the name.
-
#update_associations(name) ⇒ Object
Updates all the one-to-many relational associations for the name.
-
#update_embedded(name) ⇒ Object
Update all the dirty child documents after an update.
Instance Method Details
#associations ⇒ Object
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?
32 33 34 |
# File 'lib/mongoid/associations.rb', line 32 def 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 (name) association = send(name) association.to_a.each { |doc| doc.save if doc.changed? || doc.new_record? } unless association.blank? end |