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, #validate
Instance Method Summary collapse
-
#persist ⇒ Object
Insert the new document in the database.
Methods inherited from Command
Constructor Details
This class inherits a constructor from Mongoid::Persistence::Command
Instance Method Details
#persist ⇒ Object
Insert the new document in the database. If the document’s parent is a new record, we will call save on the parent, otherwise we will $push the document onto the parent.
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.
30 31 32 33 34 35 36 37 |
# File 'lib/mongoid/persistence/remove_embedded.rb', line 30 def persist parent = @document._parent parent.remove(@document) unless parent.new_record? update = { @document._remover => removal_selector } @collection.update(parent._selector, update, @options.merge(:multi => false)) end; true end |