简体   繁体   English

如何将每个用户的表单提交存储在rails-postgres中?

[英]How to store the submission of forms per user in rails-postgres?

I have a form with dynamic questions and dynamic input responses (Response may be a paragraph, a single word, a boolean or array of options) 我有一个包含dynamic questionsdynamic input responsesform (响应可能是一个段落,一个单词,一个布尔值或选项数组)

I need to store the submission of forms per user . 我需要store the submission of forms per user Which one is better, like I'm thinking of creating a submissions model which belongs_to both user and form with a jsonb response column and store as an array of hash which consists of a pair of question and response by the user. 哪个更好,就像我正在考虑创建一个submissions模型,该模型属于jsonb response column并属于userform ,并存储为array of hash由用户的一对question and response组成。

Or 要么

Should I map the response to each question and store them inside a answers model belongs to submissions model? 我应该将回答映射到每个问题并将它们存储在属于提交模型的答案模型中吗?

The answer depends. 答案取决于。

If the Form is a strong entity, that will not be destroyed when the user is deleted. 如果表单是一个强大的实体,则删除用户后不会破坏该实体。 Then embed it in json field is not an option. 然后将其嵌入json字段中不是一种选择。

If the Form is a weak entity, and will only be accessed along with the user. 如果表单是一个弱实体,则只能与用户一起访问。 You may store it on a json field. 您可以将其存储在json字段中。

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

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