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

Since:

  • 3.0.0



118
119
120
# File 'lib/mongoid/sessions.rb', line 118

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

Since:

  • 3.0.0



102
103
104
105
106
# File 'lib/mongoid/sessions.rb', line 102

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