Module: Mongoid::Persistable::Deletable
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
ActiveSupport::Concern
|
|
Defined in: | lib/mongoid/persistable/deletable.rb |
Overview
Defines behavior for persistence operations that delete documents.
Instance Method Summary
-
#delete(options = {}) ⇒ TrueClass
(also: #remove)
Remove the document from the database.
-
#remove(options = {})
Alias for #delete.
-
#atomic_deletes ⇒ Hash
private
Internal use only
Internal use only
Get the atomic deletes for the operation.
-
#delete_as_embedded(options = {}) ⇒ true
private
Internal use only
Internal use only
Delete the embedded document.
-
#delete_as_root ⇒ true
private
Internal use only
Internal use only
Delete the root document.
-
#notifying_parent?(options = {}) ⇒ true | false
private
Internal use only
Internal use only
Are we needing to notify the parent document of the deletion.
-
#prepare_delete {|_self| ... } ⇒ true
private
Internal use only
Internal use only
Prepare the delete operation.
Instance Method Details
#atomic_deletes ⇒ Hash (private)
This method is for internal use only.
Get the atomic deletes for the operation.
# File 'lib/mongoid/persistable/deletable.rb', line 46
def atomic_deletes { atomic_delete_modifier => { atomic_path => _index ? { "_id" => _id } : true }} end
#delete(options = {}) ⇒ TrueClass
Also known as: #remove
Remove the document from the database.
# File 'lib/mongoid/persistable/deletable.rb', line 23
def delete( = {}) prepare_delete do unless [:persist] == false if ( ) else delete_as_root end end end end
#delete_as_embedded(options = {}) ⇒ true
(private)
This method is for internal use only.
Delete the embedded document.
# File 'lib/mongoid/persistable/deletable.rb', line 60
def ( = {}) _parent.remove_child(self) if ( ) if _parent.persisted? selector = _parent.atomic_selector _root.collection.find(selector).update_one( positionally(selector, atomic_deletes), session: _session) end true end
#delete_as_root ⇒ true
(private)
This method is for internal use only.
Delete the root document.
# File 'lib/mongoid/persistable/deletable.rb', line 79
def delete_as_root collection.find(atomic_selector).delete_one(session: _session) true end
#notifying_parent?(options = {}) ⇒ true
| false
(private)
This method is for internal use only.
Are we needing to notify the parent document of the deletion.
# File 'lib/mongoid/persistable/deletable.rb', line 94
def ( = {}) ! .delete(:suppress) end
#prepare_delete {|_self| ... } ⇒ true
(private)
This method is for internal use only.
Prepare the delete operation.
# File 'lib/mongoid/persistable/deletable.rb', line 108
def prepare_delete raise Errors::ReadonlyDocument.new(self.class) if readonly? yield(self) freeze self.destroyed = true end
#remove(options = {})
Alias for #delete.
# File 'lib/mongoid/persistable/deletable.rb', line 34
alias :remove :delete