Class: Mongoid::Relations::Bindings::Referenced::Many

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

Overview

Binding class for references_many relations.

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Binding

#base, #metadata, #target

Instance Method Summary collapse

Methods inherited from Mongoid::Relations::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.posts.bind_one(post)

Parameters:

  • doc (Document)

    The single document to bind.

Since:

  • 2.0.0.rc.1



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mongoid/relations/bindings/referenced/many.rb', line 19

def bind_one(doc)
  unless _binding?
    _binding do
      doc.you_must(.foreign_key_setter, base.id)
      if .type
        doc.you_must(.type_setter, base.class.model_name)
      end
      doc.send(.inverse_setter, base)
    end
  end
end

#unbind_one(doc) ⇒ Object

Unbind a single document.

Examples:

Unbind the document.

person.posts.unbind_one(document)

Parameters:

  • document (Document)

    The document to unbind.

Since:

  • 2.0.0.rc.1



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mongoid/relations/bindings/referenced/many.rb', line 39

def unbind_one(doc)
  unless _binding?
    _binding do
      doc.you_must(.foreign_key_setter, nil)
      if .type
        doc.you_must(.type_setter, nil)
      end
      doc.send(.inverse_setter, nil)
    end
  end
end