1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

docs, AR already auto-detects primary keys. Closes #13946. [ci skip]

This behavior was introduced since Rails 3.1 (207f266cca)
but the docs were still out of date.
This commit is contained in:
Yves Senn 2014-02-05 08:52:59 +01:00
parent f92142dce1
commit 3ba0eeda02
3 changed files with 8 additions and 6 deletions

View file

@ -120,9 +120,9 @@ module ActiveRecord
# The name of the primary key, if one is to be added automatically. # The name of the primary key, if one is to be added automatically.
# Defaults to +id+. If <tt>:id</tt> is false this option is ignored. # Defaults to +id+. If <tt>:id</tt> is false this option is ignored.
# #
# Also note that this just sets the primary key in the table. You additionally # Note that Active Record models will automatically detect their
# need to configure the primary key in the model via +self.primary_key=+. # primary key. This can be avoided by using +self.primary_key=+ on the model
# Models do NOT auto-detect the primary key from their table definition. # to define the key explicitly.
# #
# [<tt>:options</tt>] # [<tt>:options</tt>]
# Any extra options you want appended to the table definition. # Any extra options you want appended to the table definition.

View file

@ -180,6 +180,11 @@ class PrimaryKeysTest < ActiveRecord::TestCase
assert !col1.equal?(col2) assert !col1.equal?(col2)
end end
end end
def test_auto_detect_primary_key_from_schema
MixedCaseMonkey.reset_primary_key
assert_equal "monkeyID", MixedCaseMonkey.primary_key
end
end end
class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
@ -214,4 +219,3 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
end end
end end
end end

View file

@ -1,5 +1,3 @@
class MixedCaseMonkey < ActiveRecord::Base class MixedCaseMonkey < ActiveRecord::Base
self.primary_key = 'monkeyID'
belongs_to :man belongs_to :man
end end