是的你可以。
首先运行迁移:
create_table 'table' id: false, force: true do |t|
t.string 'id', null: false
end
Run Code Online (Sandbox Code Playgroud)
string指定id 的类型。
然后在你的模型中:
class Table < ActiveRecord::Base
self.primary_key = :id
end
Run Code Online (Sandbox Code Playgroud)
这基本上会明确表明该字符串id是对象实例的主键。
| 归档时间: |
|
| 查看次数: |
2022 次 |
| 最近记录: |