Module: Mongoid::Persistable::Creatable

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

Overview

Defines behaviour for persistence operations that create new documents.

Since:

  • 4.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#insert(options = {}) ⇒ Document

Insert a new document into the database. Will return the document itself whether or not the save was successful.

Examples:

Insert a document.

document.insert

Parameters:

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

    Options to pass to insert.

Returns:

  • (Document)

    The persisted document.

Since:

  • 1.0.0


22
23
24
25
26
27
28
29
30
# File 'lib/mongoid/persistable/creatable.rb', line 22

def insert(options = {})
  prepare_insert(options) do
    if embedded?
      insert_as_embedded
    else
      insert_as_root
    end
  end
end