Module: Mongoid::Sessions::Options::ClassMethods

Includes:
Threaded
Defined in:
lib/mongoid/sessions/options.rb

Instance Method Summary collapse

Methods included from Threaded

#persistence_options

Instance Method Details

#with(options) ⇒ Class

Tell the next persistance operation to store in a specific collection, database or session.

Examples:

Create a document in a different collection.

Model.with(collection: "secondary").create(name: "test")

Create a document in a different database.

Model.with(database: "secondary").create(name: "test")

Create a document in a different session.

Model.with(session: "secondary").create(name: "test")

Create with a combination of options.

Model.with(session: "sharded", database: "secondary").create

Parameters:

  • options (Hash)

    The storage options.

Options Hash (options):

  • :collection (String, Symbol)

    The collection name.

  • :database (String, Symbol)

    The database name.

  • :session (String, Symbol)

    The session name.

Returns:

  • (Class)

    The model class.

Since:

  • 3.0.0



101
102
103
# File 'lib/mongoid/sessions/options.rb', line 101

def with(options)
  Proxy.new(self, (persistence_options || {}).merge(options))
end