Rails:存储一个简单的、不关联的、管理员可编辑的值
我有一个网站需要一个管理员可编辑的整数。它与数据库中的任何其他模型或属性没有关联。它实际上是一个介于 1-10,000 之间的平面整数,管理员(唯一的用户)需要访问该整数才能进行编辑。
我的问题与数据库设计有关。当然,最有效的方法不是创建自己的表,只有一列和一行?
简而言之......一个单一的领域,没有关联:我应该如何最好地滚动它?
I have a site which needs one admin-editable integer. It has no association to any other model or attribute in the database. It's literally a flat integer, between 1-10,000, that the admin (who is the only user) needs access to edit.
My question relates to database design. Surely the most efficient way to do this isn't to create its own table, with just one single column and one single row?
In short...one single field, no associations: how should I best roll that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于你如何定义“高效”。
如果将“高效”定义为
那么创建单行表可能是最有效的。沿着这些思路的东西可能会在数据库方面起作用。
我认为 Rails 不支持 CHECK 约束,因此我认为您需要在迁移中传递 ALTER TABLE SQL 语句。
It depends on how you define "efficient".
If you define "efficient" as using
then creating a one-row table probably is the most efficient. Something along these lines might work on the database side.
I don't think rails supports CHECK constraints, so I think you'll need to pass
ALTER TABLE
SQL statements in the migration.