Module: Mongoid::Persistable::Destroyable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mongoid::Persistable
- Defined in:
- lib/mongoid/persistable/destroyable.rb
Overview
Defines behavior for persistence operations that destroy documents.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#destroy(options = nil) ⇒ true, false
Remove the document from the database with callbacks.
- #destroy!(options = {}) ⇒ Object
Instance Method Details
#destroy(options = nil) ⇒ true, false
Remove the document from the database with callbacks.
23 24 25 26 27 28 29 |
# File 'lib/mongoid/persistable/destroyable.rb', line 23 def destroy( = nil) raise Errors::ReadonlyDocument.new(self.class) if readonly? self.flagged_for_destroy = true result = run_callbacks(:destroy) { delete( || {}) } self.flagged_for_destroy = false result end |
#destroy!(options = {}) ⇒ Object
31 32 33 |
# File 'lib/mongoid/persistable/destroyable.rb', line 31 def destroy!( = {}) destroy || raise(Errors::DocumentNotDestroyed.new(id, self.class)) end |