在数据库中存储多个复选框值

发布于 2024-08-27 20:52:44 字数 247 浏览 5 评论 0原文

我想在表中存储多个列值。让我们举个例子..您最喜欢的颜色是什么?选择可以是红色、蓝色、绿色、橙色。因此,假设用户至少选择 2 个值。

有什么办法可以将多个值存储在表中。我通过将用户的选择连接到表的一列中来实现。后来我发现这是一个不好的做法。

目前我可以考虑使用按位运算符和 habtm。

在表中存储多个选择值有哪些不同方法? 如果我在 Rails 中实现,使用 OOP 概念实现这一点的最佳方法是什么? Rails 中有内置选项吗?

I want to store multiple column values in table.Lets take a example .. What are your favourite colors? the choices can be red,blue,green, orange. So lets assume, the user selects atleast 2 values.

Is there any way to store the multiple values in table. I have implemented by concatinating choices of users in a column in the table. I later found that it is a bad practise.

Currently i can think of using Bitwise operator and habtm.

What are the different ways for storing multiple choices values in table?
If I am implementing in rails, What is the best way to implement this with OOP concepts?
Is there any builtin options in rails?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-09-03 20:52:45

通常的解决方案是使用桥接表来创建 多对多关系

The usual solution is to have a bridging table to create a many-to-many relationship.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文