Class: Mongoid::Association::Embedded::EmbedsMany::Binding

Inherits:
Object
  • Object
show all
Includes:
Bindable
Defined in:
lib/mongoid/association/embedded/embeds_many/binding.rb

Overview

Binding class for all embeds_many associations.

Instance Attribute Summary

Attributes included from Bindable

#_association, #_base, #_target

Instance Method Summary collapse

Methods included from Bindable

#binding, #initialize

Instance Method Details

#bind_one(doc) ⇒ Object

Binds a single document with the inverse association. Used specifically when appending to the proxy.

Examples:

Bind one document.

person.addresses.bind_one(address)

Parameters:

  • doc (Document)

    The single document to bind.



20
21
22
23
24
25
26
# File 'lib/mongoid/association/embedded/embeds_many/binding.rb', line 20

def bind_one(doc)
  doc.parentize(_base)
  binding do
    remove_associated(doc)
    try_method(doc, _association.inverse_setter(_target), _base)
  end
end

#unbind_one(doc) ⇒ Object

Unbind a single document.

Examples:

Unbind the document.

person.addresses.unbind_one(document)

Parameters:

  • doc (Document)

    The single document to unbind.



34
35
36
37
38
# File 'lib/mongoid/association/embedded/embeds_many/binding.rb', line 34

def unbind_one(doc)
  binding do
    try_method(doc, _association.inverse_setter(_target), nil)
  end
end