Module: Mongoid::Persistable::Deletable

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

Overview

Defines behavior for persistence operations that delete documents.

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: {})

    The options.

Options Hash (options):

  • :persist (true | false)

    Whether to persist the delete action.

  • :suppress (true | false)

    Whether to update the parent document in-memory when deleting an embedded document.

Returns:

  • (TrueClass)

    True.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mongoid/persistable/deletable.rb', line 23

def delete(options = {})
  prepare_delete do
    unless options[:persist] == false
      if embedded?
        delete_as_embedded(options)
      else
        delete_as_root
      end
    end
  end
end