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

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

Overview

Binding class for all embeds_many associations.

Since:

  • 7.0

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.

Since:

  • 2.0.0.rc.1



24
25
26
27
28
29
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/binding.rb', line 24

def bind_one(doc)
  doc.parentize(_base)
  binding do
    doc.do_or_do_not(_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.

Since:

  • 2.0.0.rc.1



39
40
41
42
43
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/binding.rb', line 39

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