module ActiveModelPersistence::PrimaryKeyIndex::ClassMethods
When this module is included in another class, ActiveSupport::Concern will make these class methods on that class.
Public Class Methods
extended(base)
click to toggle source
Create the primary key index
@return [void]
@api private
# File lib/active_model_persistence/primary_key_index.rb, line 49 def self.extended(base) base.index('primary_key', key_value_source: :primary_key, unique: true) end
Public Instance Methods
find(primary_key_value)
click to toggle source
Finds an object in the :primary_key index whose primary matches the given value
@example
class Employee include ActiveModelPersistence::PrimaryKeyIndex attribute :id, :integer end e1 = Employee.new(id: 1) e1.update_indexes Employee.find(1) #=> e1 Employee.find(2) #=> nil
@param primary_key_value [Object] The primary key value to find in the :primary_key index
@return [Object, nil] The object in the :primary_key index whose primary matches the given value
# File lib/active_model_persistence/primary_key_index.rb, line 39 def find(primary_key_value) find_by_primary_key(primary_key_value).first end