module ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods

def dangerous_attribute_method?(method_name)

def dangerous_attribute_method?(method_name)
  super && !ID_ATTRIBUTE_METHODS.include?(method_name)
end

def get_primary_key(base_name) # :nodoc:

:nodoc:
def get_primary_key(base_name) # :nodoc:
  if base_name && primary_key_prefix_type == :table_name
    base_name.foreign_key(false)
  elsif base_name && primary_key_prefix_type == :table_name_with_underscore
    base_name.foreign_key
  else
    if ActiveRecord::Base != self && table_exists?
      pk = connection.schema_cache.primary_keys(table_name)
      suppress_composite_primary_key(pk)
    else
      "id"
    end
  end
end

def instance_method_already_implemented?(method_name)

def instance_method_already_implemented?(method_name)
  super || primary_key && ID_ATTRIBUTE_METHODS.include?(method_name)
end

def primary_key

setting, though.
Overwriting will negate any effect of the +primary_key_prefix_type+
Defines the primary key field -- can be overridden in subclasses.
def primary_key
  @primary_key = reset_primary_key unless defined? @primary_key
  @primary_key
end

def primary_key=(value)

Project.primary_key # => "foo_id"

end
end
'foo_' + super
def self.primary_key
class Project < ActiveRecord::Base

You can also define the #primary_key method yourself:

end
self.primary_key = 'sysid'
class Project < ActiveRecord::Base

Sets the name of the primary key column.
def primary_key=(value)
  @primary_key        = value && -value.to_s
  @quoted_primary_key = nil
  @attributes_builder = nil
end

def quoted_primary_key

SQL statements.
Returns a quoted version of the primary key name, used to construct
def quoted_primary_key
  @quoted_primary_key ||= connection.quote_column_name(primary_key)
end

def reset_primary_key # :nodoc:

:nodoc:
def reset_primary_key # :nodoc:
  if base_class?
    self.primary_key = get_primary_key(base_class.name)
  else
    self.primary_key = base_class.primary_key
  end
end

def suppress_composite_primary_key(pk)

def suppress_composite_primary_key(pk)
  return pk unless pk.is_a?(Array)
  warn <<~WARNING
    WARNING: Active Record does not support composite primary key.
    #{table_name} has composite primary key. Composite primary key is ignored.
  WARNING
end