在数据库中存储多个复选框值
我想在表中存储多个列值。让我们举个例子..您最喜欢的颜色是什么?选择可以是红色、蓝色、绿色、橙色。因此,假设用户至少选择 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常的解决方案是使用桥接表来创建 多对多关系。
The usual solution is to have a bridging table to create a many-to-many relationship.