Method: ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods#primary_key=
- Defined in:
- activerecord/lib/active_record/attribute_methods/primary_key.rb
#primary_key=(value) ⇒ Object
Sets the name of the primary key column.
class Project < ActiveRecord::Base
self.primary_key = 'sysid'
end
You can also define the #primary_key method yourself:
class Project < ActiveRecord::Base
def self.primary_key
'foo_' + super
end
end
Project.primary_key # => "foo_id"
130 131 132 133 134 135 136 137 138 139 140 |
# File 'activerecord/lib/active_record/attribute_methods/primary_key.rb', line 130 def primary_key=(value) @primary_key = if value.is_a?(Array) include CompositePrimaryKey @primary_key = value.map { |v| -v.to_s }.freeze elsif value -value.to_s end @composite_primary_key = value.is_a?(Array) @attributes_builder = nil end |