Create an ActiveRecord database table with no :id column?(创建一个没有 :id 列的 ActiveRecord 数据库表?)
问题描述
我是否可以在 Ruby on Rails 的 ActiveRecord 中创建和使用不包含 :id 列的数据库表.
Is it possible for me to create and use a database table that contains no :id column in ActiveRecord, Ruby on Rails.
我不只是想忽略 id 列,但我希望它绝对不存在.
I don't merely want to ignore the id column, but I wish it to be absolutely non-existent.
Table Example
:key_column :value_column
0cc175b9c0f1b6a831c399e269772661 0cc175b9c0f1b6a831c399e269772661
4a8a08f09d37b73795649038408b5f33 0d61f8370cad1d412f80b84d143e1257
92eb5ffee6ae2fec3ad71c777531578f 9d5ed678fe57bcca610140957afab571
任何更多信息(如 :id_column )都会破坏整个功能.
Any more info ( like an :id_column ) would break the whole feature.
我将如何在 Rails 中实现这样的功能?
How would I implement something like this in rails?
推荐答案
是的,看起来像这样:
create_table :my_table, id: false do |t|
t.string :key_column
t.string :value_column
end
只要确保包含
id: false
部分.
这篇关于创建一个没有 :id 列的 ActiveRecord 数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建一个没有 :id 列的 ActiveRecord 数据库表?
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
