Module: Mongoid::Persistable::Destroyable

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Persistable
Defined in:
lib/mongoid/persistable/destroyable.rb

Overview

Defines behaviour for persistence operations that destroy documents.

Since:

  • 4.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroy(options = nil) ⇒ true, false

Remove the document from the database with callbacks.

Examples:

Destroy a document.

document.destroy

Raises:

Since:

  • 1.0.0



21
22
23
24
25
26
27
# File 'lib/mongoid/persistable/destroyable.rb', line 21

def destroy(options = nil)
  raise Errors::ReadonlyDocument.new(self.class) if readonly?
  self.flagged_for_destroy = true
  result = run_callbacks(:destroy) { delete(options || {}) }
  self.flagged_for_destroy = false
  result
end

#destroy!(options = {}) ⇒ Object

Since:

  • 4.0.0



29
30
31
# File 'lib/mongoid/persistable/destroyable.rb', line 29

def destroy!(options = {})
  destroy || raise(Errors::DocumentNotDestroyed.new(id, self.class))
end