Class: Mongoid::Relations::Bindings::Embedded::Many

Inherits:
Mongoid::Relations::Binding show all
Defined in:
lib/mongoid/relations/bindings/embedded/many.rb

Overview

Binding class for embeds_many relations.

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Binding

#base, #metadata, #target

Instance Method Summary collapse

Methods inherited from Mongoid::Relations::Binding

#binding, #initialize

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.

Examples:

Bind one document.

person.addresses.bind_one(address)

Parameters:

  • doc (Document)

    The single document to bind.

  • options (Hash)

    The binding options.

Since:

  • 2.0.0.rc.1



23
24
25
26
27
28
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 23

def bind_one(doc)
  doc.parentize(base)
  binding do
    doc.do_or_do_not(.inverse_setter(target), base)
  end
end

#unbind_one(doc) ⇒ Object

Unbind a single document.

Examples:

Unbind the document.

person.addresses.unbind_one(document)

Parameters:

  • options (Hash)

    The binding options.

Since:

  • 2.0.0.rc.1



41
42
43
44
45
# File 'lib/mongoid/relations/bindings/embedded/many.rb', line 41

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