Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

This behavior was introduced since Rails 3.1 (207f266)
but the docs were still out of date.
  • Loading branch information...
commit 3ba0eeda02e85c312d2867afc4aa9afea50d93ec 1 parent f92142d
@senny senny authored
View
6 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -120,9 +120,9 @@ def column_exists?(table_name, column_name, type = nil, options = {})
# 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.
View
6 activerecord/test/cases/primary_keys_test.rb
@@ -180,6 +180,11 @@ def test_models_with_same_table_have_different_columns
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 @@ def test_primary_key_method_with_ansi_quotes
end
end
end
-
View
2  activerecord/test/models/mixed_case_monkey.rb
@@ -1,5 +1,3 @@
class MixedCaseMonkey < ActiveRecord::Base
- self.primary_key = 'monkeyID'
-
belongs_to :man
end
Please sign in to comment.
Something went wrong with that request. Please try again.