Skip to content

Commit bb45fa0

Browse files
kamipojeremy
authored andcommitted
Deprecate supports_primary_key?
`supports_primary_key?` was added to determine if `primary_key` is implemented in the adapter in f060221. But we already use `primary_key` without `supports_primary_key?` (207f266, 5f3cf42) and using `supports_primary_key?` has been removed in rails#1318. This means that `supports_primary_key?` is no longer used in the internal and Active Record doesn't work without `primary_key` is implemented (all adapters must implement `primary_key`). Closes rails#27977
1 parent 416d85b commit bb45fa0

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

activerecord/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Deprecate `supports_primary_key?` on connection adapters since it's
2+
been long unused and unsupported.
3+
4+
*Ryuta Kamizono*
5+
16
* Make `table_name=` reset current statement cache,
27
so queries are not run against the previous table name.
38

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@ def supports_migrations?
236236
false
237237
end
238238

239-
# Can this adapter determine the primary key for tables not attached
240-
# to an Active Record class, such as join tables?
241-
def supports_primary_key?
242-
false
239+
def supports_primary_key? # :nodoc:
240+
true
243241
end
242+
deprecate :supports_primary_key?
244243

245244
# Does this adapter support DDL rollbacks in transactions? That is, would
246245
# CREATE TABLE or ALTER TABLE get rolled back by a transaction?

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ def supports_migrations?
9393
true
9494
end
9595

96-
def supports_primary_key?
97-
true
98-
end
99-
10096
def supports_bulk_alter? #:nodoc:
10197
true
10298
end

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ def supports_migrations?
282282
true
283283
end
284284

285-
# Does PostgreSQL support finding primary key on non-Active Record tables?
286-
def supports_primary_key? #:nodoc:
287-
true
288-
end
289-
290285
def set_standard_conforming_strings
291286
execute("SET standard_conforming_strings = on", "SCHEMA")
292287
end

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ def supports_migrations? #:nodoc:
122122
true
123123
end
124124

125-
def supports_primary_key? #:nodoc:
126-
true
127-
end
128-
129125
def requires_reloading?
130126
true
131127
end

activerecord/test/cases/primary_keys_test.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,24 @@ def test_instance_destroy_should_quote_pkey
141141
assert_nothing_raised { MixedCaseMonkey.find(1).destroy }
142142
end
143143

144-
if ActiveRecord::Base.connection.supports_primary_key?
145-
def test_primary_key_returns_value_if_it_exists
146-
klass = Class.new(ActiveRecord::Base) do
147-
self.table_name = "developers"
148-
end
144+
def test_deprecate_supports_primary_key
145+
assert_deprecated { ActiveRecord::Base.connection.supports_primary_key? }
146+
end
149147

150-
assert_equal "id", klass.primary_key
148+
def test_primary_key_returns_value_if_it_exists
149+
klass = Class.new(ActiveRecord::Base) do
150+
self.table_name = "developers"
151151
end
152152

153-
def test_primary_key_returns_nil_if_it_does_not_exist
154-
klass = Class.new(ActiveRecord::Base) do
155-
self.table_name = "developers_projects"
156-
end
153+
assert_equal "id", klass.primary_key
154+
end
157155

158-
assert_nil klass.primary_key
156+
def test_primary_key_returns_nil_if_it_does_not_exist
157+
klass = Class.new(ActiveRecord::Base) do
158+
self.table_name = "developers_projects"
159159
end
160+
161+
assert_nil klass.primary_key
160162
end
161163

162164
def test_quoted_primary_key_after_set_primary_key

0 commit comments

Comments
 (0)