Class: Mongoid::Persistence::Operations::Embedded::Remove

Inherits:
Object
  • Object
show all
Includes:
Deletion, Mongoid::Persistence::Operations
Defined in:
lib/mongoid/persistence/operations/embedded/remove.rb

Overview

Remove is a persistence command responsible for deleting a document from the database.

The underlying query resembles the following MongoDB query:

collection.remove(
  { "_id" : 1 },
  false
);

Instance Attribute Summary

Attributes included from Mongoid::Persistence::Operations

#conflicts, #document

Instance Method Summary collapse

Methods included from Deletion

#prepare

Methods included from Mongoid::Persistence::Operations

#collection, #deletes, #initialize, insert, #inserts, #notifying_parent?, #options, #parent, remove, #selector, update, #updates, #validating?

Instance Method Details

#persisttrue

Remove the document from the database. If the parent is a new record, it will get removed in Ruby only. If the parent is not a new record then either an $unset or $set will occur, depending if it’s an embeds_one or embeds_many.

Examples:

Remove an embedded document.

RemoveEmbedded.persist

Returns:

  • (true)

    Always true.



28
29
30
31
32
33
34
35
# File 'lib/mongoid/persistence/operations/embedded/remove.rb', line 28

def persist
  prepare do |doc|
    parent.remove_child(doc) if notifying_parent?
    if parent.persisted?
      collection.update(parent.atomic_selector, deletes, options)
    end
  end
end