Module: Mongoid::Sessions::ClassMethods

Defined in:
lib/mongoid/sessions.rb

Instance Method Summary collapse

Instance Method Details

#collectionMoped::Collection

Get the collection for this model from the session. Will check for an overridden collection name from the store_in macro or the collection with a pluralized model name.

Examples:

Get the model’s collection.

Model.collection

Returns:

  • (Moped::Collection)

    The collection.

Since:

  • 3.0.0



120
121
122
# File 'lib/mongoid/sessions.rb', line 120

def collection
  mongo_session[collection_name]
end

#mongo_sessionMoped::Session

Get the session for this model. This is determined in the following order:

1. Any custom configuration provided by the 'store_in' macro.
2. The 'default' session as provided in the mongoid.yml

Examples:

Get the session.

Model.mongo_session

Returns:

  • (Moped::Session)

    The default moped session.

Since:

  • 3.0.0



104
105
106
107
108
# File 'lib/mongoid/sessions.rb', line 104

def mongo_session
  session = Sessions.with_name(session_name)
  session.use(database_name)
  self.persistence_options ? session.with(self.persistence_options) : session
end