提交 4bb65a8f 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #27935 from namusyaka/fix-hidden-primary_key

Fix inspection behavior when the :id column is not primary key
* Fix inspection behavior when the :id column is not primary key.
*namusyaka*
* Deprecate locking records with unpersisted changes.
*Marc Schütz*
......
......@@ -54,7 +54,7 @@ def read_attribute(attr_name, &block)
attr_name.to_s
end
name = self.class.primary_key if name == "id".freeze
name = self.class.primary_key if name == "id".freeze && self.class.primary_key
_read_attribute(name, &block)
end
......
......@@ -7,6 +7,7 @@
require "models/keyboard"
require "models/mixed_case_monkey"
require "models/dashboard"
require "models/non_primary_key"
class PrimaryKeysTest < ActiveRecord::TestCase
fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
......@@ -89,6 +90,12 @@ def test_string_key
assert_equal("John Doe", subscriberReloaded.name)
end
def test_id_column_that_is_not_primary_key
NonPrimaryKey.create!(id: 100)
actual = NonPrimaryKey.find_by(id: 100)
assert_match %r{<NonPrimaryKey id: 100}, actual.inspect
end
def test_find_with_more_than_one_string_key
assert_equal 2, Subscriber.find(subscribers(:first).nick, subscribers(:second).nick).length
end
......
class NonPrimaryKey < ActiveRecord::Base
end
......@@ -1039,6 +1039,10 @@
create_table :test_with_keyword_column_name, force: true do |t|
t.string :desc
end
create_table :non_primary_keys, force: true, id: false do |t|
t.integer :id
end
end
Course.connection.create_table :courses, force: true do |t|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册