Class: Mongoid::Persistence::RemoveEmbedded
- Defined in:
- lib/mongoid/persistence/remove_embedded.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 inherited from Command
#collection, #document, #klass, #options, #selector, #suppress, #validate
Instance Method Summary collapse
-
#persist ⇒ Object
Remove the document from the database.
Methods inherited from Command
Methods included from Safe
Constructor Details
This class inherits a constructor from Mongoid::Persistence::Command
Instance Method Details
#persist ⇒ Object
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.
Example:
RemoveEmbedded.persist
Returns:
true
or false
, depending on if the removal passed.
28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/persistence/remove_embedded.rb', line 28 def persist parent = document._parent parent.remove_child(document) unless suppress? unless parent.new_record? update = { document._remover => removal_selector } collection.update(parent._selector, update, .merge(:multi => false)) end; true end |