Module: ActiveModelPersistence::Indexable
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, PrimaryKey
- Included in:
- Persistence, PrimaryKeyIndex
- Defined in:
- lib/active_model_persistence/indexable.rb
Overview
Include in your model to enable index support
Define an index in the model’s class using the ‘index` method. This will create a `find_by_*` method for each index to find the objects by their keys.
Each index has a name which must be unique for the model. The name is used to create the ‘find_by_*` method. eg. for the ’id’ index, the ‘find_by_id` method will be created.
Unique indexes are defined by passing ‘unique: true` to the `index` method. A unique index defines a `find_by_*` method that will return a single object or nil if no object is found for the key.
A non-unique index will define a ‘find_by_*` method that will return an array of objects which may be empty.
Defined Under Namespace
Modules: ClassMethods