Module: Mongoid::Persistable::Creatable

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

Overview

Defines behavior for persistence operations that create new documents.

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.



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

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