Class: Mongoid::Association::Embedded::EmbedsMany::Proxy

Inherits:
Association::Many
  • Object
show all
Defined in:
lib/mongoid/paranoia/monkey_patches.rb,
lib/mongoid/paranoia/monkey_patches.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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mongoid/paranoia/monkey_patches.rb', line 65

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



104
105
106
# File 'lib/mongoid/paranoia/monkey_patches.rb', line 104

def deleted
  unscoped.deleted
end