# File lib/active_model_persistence/primary_key.rb, line 59 def primary_key @primary_key ||= 'id' end
module ActiveModelPersistence::PrimaryKey::ClassMethods
When this module is included in another class, ActiveSupport::Concern will make these class methods on that class.
Public Instance Methods
primary_key()
click to toggle source
Identifies the attribute that the ‘primary_key` accessor maps to
The primary key is ‘id’ by default.
@example
class Employee include ActiveModelPersistence::PrimaryKey attribute :username, :string self.primary_key = :username end Employee.primary_key #=> :username
@return [Symbol] the attribute that the ‘primary_key` accessor is an alias for
primary_key=(attribute)
click to toggle source
Sets the attribute to use for the primary key
@example
class Employee include ActiveModelPersistence::PrimaryKey attribute :username, :string primary_key = :username end e = Employee.new(username: 'couballj') e.primary_key #=> 'couballj'
@param attribute [Symbol] the attribute to use for the primary key
@return [void]
# File lib/active_model_persistence/primary_key.rb, line 78 def primary_key=(attribute) @primary_key = attribute.to_s end