简体   繁体   English

如何在Rails 4(postgres db)中存储值对

[英]How to store value pairs in Rails 4 (postgres db)

I'm trying to store two types of product identifications together, one for each product color for each product. 我正在尝试将两种类型的产品标识存储在一起,一种用于每种产品的每种颜色。

I want to do this without creating another table, just by storing a set of id pairs. 我只想存储一组ID对,而不创建另一个表就可以做到这一点。 My form looks like this: 我的表格如下所示:

在此处输入图片说明

How can i submit and store this data in a consistent way? 如何以一致的方式提交和存储此数据? Is Hstore a good alternative for this? Hstore是否是一个不错的选择?

Why don't you want to create another table? 您为什么不想创建另一个表? Your data model seems to necessitate it. 您的数据模型似乎是必需的。 I would recommend avoiding database-specific solutions when a Rails-based one (adding another model) would be more universal and is trivially supported. 当基于Rails的解决方案(添加另一种模型)更加通用并且受到支持时,我建议避免使用特定于数据库的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM