Module: Mongoid::Persistable::Deletable

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Persistable
Defined in:
build/mongoid-6.1/lib/mongoid/persistable/deletable.rb

Overview

Defines behaviour for persistence operations that delete documents.

Since:

  • 4.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#delete(options = {}) ⇒ TrueClass Also known as: remove

Remove the document from the database.

Examples:

Remove the document.

document.remove

Parameters:

  • options (Hash) (defaults to: {})

    Options to pass to remove.

Returns:

  • (TrueClass)

    True.

Raises:

Since:

  • 1.0.0



21
22
23
24
25
26
27
28
29
30
# File 'build/mongoid-6.1/lib/mongoid/persistable/deletable.rb', line 21

def delete(options = {})
  raise Errors::ReadonlyDocument.new(self.class) if readonly?
  prepare_delete do
    if embedded?
      delete_as_embedded(options)
    else
      delete_as_root
    end
  end
end