Class: Mongoid::Relations::Bindings::Embedded::Many
- Inherits:
-
Mongoid::Relations::Binding
- Object
- Mongoid::Relations::Binding
- Mongoid::Relations::Bindings::Embedded::Many
- Defined in:
- lib/mongoid/relations/bindings/embedded/many.rb
Overview
Binding class for embeds_many relations.
Constant Summary
Constants inherited from Mongoid::Relations::Binding
Mongoid::Relations::Binding::OPTIONS
Instance Attribute Summary
Attributes inherited from Mongoid::Relations::Binding
Instance Method Summary collapse
-
#bind(options = {}) ⇒ Object
Binds the base object to the inverse of the relation.
-
#bind_one(doc, options = {}) ⇒ Object
Binds a single document with the inverse relation.
-
#unbind(options = {}) ⇒ Object
Unbinds the base object and the inverse, caused by setting the reference to nil.
-
#unbind_one(doc, options = {}) ⇒ Object
Unbind a single document.
Methods inherited from Mongoid::Relations::Binding
Constructor Details
This class inherits a constructor from Mongoid::Relations::Binding
Instance Method Details
#bind(options = {}) ⇒ Object
Binds the base object to the inverse of the relation. This is so we are referenced to the actual objects themselves on both sides.
This case sets the metadata on the inverse object as well as the document itself.
26 27 28 |
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 26 def bind( = {}) target.each { |doc| bind_one(doc, ) } end |
#bind_one(doc, options = {}) ⇒ Object
Binds a single document with the inverse relation. Used specifically when appending to the proxy.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 43 def bind_one(doc, = {}) doc.parentize(base) if [:continue] name = .inverse_setter(target) doc.do_or_do_not( name, base, :binding => true, :continue => false ) unless name == "versions=" end end |
#unbind(options = {}) ⇒ Object
Unbinds the base object and the inverse, caused by setting the reference to nil.
69 70 71 |
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 69 def unbind( = {}) target.each { |doc| unbind_one(doc, ) } end |
#unbind_one(doc, options = {}) ⇒ Object
Unbind a single document.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 84 def unbind_one(doc, = {}) if [:continue] doc.do_or_do_not( .inverse_setter(target), nil, :binding => true, :continue => false ) end end |