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:
parent
f92142dce1
commit
3ba0eeda02
3 changed files with 8 additions and 6 deletions
|
@ -120,9 +120,9 @@ module ActiveRecord
|
|||
# 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.
|
||||
#
|
||||
# Also note that this just sets the primary key in the table. You additionally
|
||||
# need to configure the primary key in the model via +self.primary_key=+.
|
||||
# Models do NOT auto-detect the primary key from their table definition.
|
||||
# Note that Active Record models will automatically detect their
|
||||
# primary key. This can be avoided by using +self.primary_key=+ on the model
|
||||
# to define the key explicitly.
|
||||
#
|
||||
# [<tt>:options</tt>]
|
||||
# Any extra options you want appended to the table definition.
|
||||
|
|
|
@ -180,6 +180,11 @@ class PrimaryKeysTest < ActiveRecord::TestCase
|
|||
assert !col1.equal?(col2)
|
||||
end
|
||||
end
|
||||
|
||||
def test_auto_detect_primary_key_from_schema
|
||||
MixedCaseMonkey.reset_primary_key
|
||||
assert_equal "monkeyID", MixedCaseMonkey.primary_key
|
||||
end
|
||||
end
|
||||
|
||||
class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
|
||||
|
@ -214,4 +219,3 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
class MixedCaseMonkey < ActiveRecord::Base
|
||||
self.primary_key = 'monkeyID'
|
||||
|
||||
belongs_to :man
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue