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

Inherits:
Relations::Many
  • Object
show all
Defined in:
lib/mongoid/core_ext/relations/embedded/many.rb

Instance Method Summary collapse

Instance Method Details

#delete(document) ⇒ Document?

Delete the supplied document from the target. This method is proxied in order to reindex the array after the operation occurs.

Examples:

Delete the document from the relation.

person.addresses.delete(address)

Parameters:

  • document (Document)

    The document to be deleted.

Returns:

  • (Document, nil)

    The deleted document or nil if nothing deleted.

Since:

  • 2.0.0.rc.1



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mongoid/core_ext/relations/embedded/many.rb', line 18

def delete(document)
  execute_callback :before_remove, document
  doc = target.delete_one(document)
  if doc && !_binding?
    _unscoped.delete_one(doc) unless doc.paranoid?
    if _assigning?
      if doc.paranoid?
        doc.destroy(suppress: true)
      else
        base.add_atomic_pull(doc)
      end
    else
      doc.delete(suppress: true)
      unbind_one(doc)
    end
  end
  reindex
  execute_callback :after_remove, document
  doc
end

#deletedCriteria

For use only with Mongoid::Paranoia - will be removed in 4.0.

Examples:

Get the deleted documents from the relation.

person.paranoid_phones.deleted

Returns:

  • (Criteria)

    The deleted documents.

Since:

  • 3.0.10



47
48
49
# File 'lib/mongoid/core_ext/relations/embedded/many.rb', line 47

def deleted
  unscoped.deleted
end