Module: Mongoid::Persistence::Deletion

Included in:
Operations::Embedded::Remove, Operations::Remove
Defined in:
lib/mongoid/persistence/deletion.rb

Overview

Contains common logic for delete operations.

Instance Method Summary collapse

Instance Method Details

#prepare(&block) {|document| ... } ⇒ true

Wrap all the common delete logic for both root and embedded documents and then yield to the block.

Examples:

Execute common delete logic.

prepare do |doc|
  collection.remove({ :_id => "value })
end

Parameters:

  • block (Proc)

    The block to call.

Yields:

  • (document)

Returns:

  • (true)

    Always true.

Since:

  • 2.1.0



21
22
23
24
25
26
27
28
29
# File 'lib/mongoid/persistence/deletion.rb', line 21

def prepare(&block)
  document.cascade!
  yield(document)
  document.freeze
  document.destroyed = true
  IdentityMap.remove(document)
  Threaded.clear_options!
  true
end