Class: Mongoid::Relations::Bindings::Referenced::ManyToMany
- Inherits:
-
Mongoid::Relations::Binding
- Object
- Mongoid::Relations::Binding
- Mongoid::Relations::Bindings::Referenced::ManyToMany
- Defined in:
- lib/mongoid/relations/bindings/referenced/many_to_many.rb
Overview
Binding class for all references_and_referenced_in_many relations.
Instance Attribute Summary
Attributes inherited from Mongoid::Relations::Binding
Instance Method Summary collapse
-
#bind_one(doc) ⇒ Object
Binds a single document with the inverse relation.
-
#unbind_one(doc) ⇒ 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_one(doc) ⇒ Object
Binds a single document with the inverse relation. Used specifically when appending to the proxy.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mongoid/relations/bindings/referenced/many_to_many.rb', line 19 def bind_one(doc) unless _binding? _binding do inverse_keys = doc.you_must(.inverse_foreign_key) inverse_keys.push(base.id) if inverse_keys base.synced[.foreign_key] = true doc.synced[.inverse_foreign_key] = true end end end |
#unbind_one(doc) ⇒ Object
Unbind a single document.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mongoid/relations/bindings/referenced/many_to_many.rb', line 36 def unbind_one(doc) unless _binding? _binding do base.send(.foreign_key).delete_one(doc.id) inverse_keys = doc.you_must(.inverse_foreign_key) inverse_keys.delete_one(base.id) if inverse_keys base.synced[.foreign_key] = true doc.synced[.inverse_foreign_key] = true end end end |