Skip to content
Browse files

docs, AR already auto-detects primary keys. Closes #13946.

This behavior was introduced since Rails 3.1 (207f266)
but the docs were still out of date.

Conflicts:
	activerecord/test/models/mixed_case_monkey.rb
  • Loading branch information...
1 parent bff8c2c commit 9369486c71a6a330eb6aff07f3f46122dafca114 @senny senny committed Feb 5, 2014
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
@@ -215,4 +220,3 @@ def test_primaery_key_method_with_ansi_quotes
end
end
-
View
1 activerecord/test/models/mixed_case_monkey.rb
@@ -1,3 +1,2 @@
class MixedCaseMonkey < ActiveRecord::Base
- self.primary_key = 'monkeyID'
end

0 comments on commit 9369486

Please sign in to comment.
Something went wrong with that request. Please try again.