创建一个ActiveRecord数据库表没有:id列? [英] Create an ActiveRecord database table with no :id column?

查看:149
本文介绍了创建一个ActiveRecord数据库表没有:id列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能对我来说,创建和使用的数据库表不包含任何:ID 列的ActiveRecord,Ruby on Rails的

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.

我将如何实现这样的事情在轨?

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

只要确保包括

just make sure to include the

id: false

部分。

这篇关于创建一个ActiveRecord数据库表没有:id列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆