module Mongoid::Persistable::Destroyable
Defines behavior for persistence operations that destroy documents.
@since 4.0.0
Public Instance Methods
destroy(options = nil)
click to toggle source
Remove the document from the database with callbacks.
@example Destroy a document.
document.destroy
@param [ Hash ] options Options to pass to destroy.
@return [ true, false ] True if successful, false if not.
@since 1.0.0
# File lib/mongoid/persistable/destroyable.rb, line 23 def destroy(options = nil) raise Errors::ReadonlyDocument.new(self.class) if readonly? self.flagged_for_destroy = true result = run_callbacks(:destroy) do if catch(:abort) { apply_destroy_dependencies! } delete(options || {}) else false end end self.flagged_for_destroy = false result end
destroy!(options = {})
click to toggle source
# File lib/mongoid/persistable/destroyable.rb, line 37 def destroy!(options = {}) destroy || raise(Errors::DocumentNotDestroyed.new(_id, self.class)) end