Class: Mongoid::Association::Nested::Many

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/paranoia/monkey_patches.rb

Instance Method Summary collapse

Instance Method Details

#destroy(parent, relation, doc) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Destroy the child document, needs to do some checking for embedded relations and delay the destroy in case parent validation fails.

Examples:

Destroy the child.

builder.destroy(parent, relation, doc)

Parameters:

  • parent (Document)

    The parent document.

  • relation (Proxy)

    The relation proxy.

  • doc (Document)

    The doc to destroy.

Since:

  • 3.0.10



36
37
38
39
40
41
42
43
# File 'lib/mongoid/paranoia/monkey_patches.rb', line 36

def destroy(parent, relation, doc)
  doc.flagged_for_destroy = true
  if !doc.embedded? || parent.new_record? || doc.paranoid?
    destroy_document(relation, doc)
  else
    parent.flagged_destroys.push(->{ destroy_document(relation, doc) })
  end
end