1

To summarise, I have a list of questions in table questions, a list of possible answers in table answers and a table called user_answers with the selected answers from the users.

There are endpoints in my application that allow the user to display the questions and answers, answer them and display a summary of the questions for the user.

Currently, I handle this data model by creating all answers related to a user on user creation (they are unchecked by default). This way of handling things allows us to always know that a user answer is available (the user_answer model has some fields that are updated dynamicaly and knowing that the record are already there simplifies some logic). On the other hand, it seems weird to create a lot of empty records in the database for this.

What are the good practices related to this kind of problem?

Should I create records in user_answers only when the user answers a question or is this OK to create all records from the beginning?

Thank you

  • It's not quite clear why you pre-generate answers to questions for a user who hasn't actually attempted to answer the question yet? What's the benefit in doing so? – J.D. Jul 19 '22 at 02:01
  • Sometimes, I need to update all the answers of a specific group of users. It is simpler to assume that all the answers exist and do a batch update instead of trying to figure out which answers need to be created and doing a batch update after that – clementescolano Jul 19 '22 at 07:53
  • Still not following. If you could update your post with your table definitions, example data, and a demonstration of that use case where you "need to update all the answers of a specific group of users" showing the before and after data, that would probably help. From the names of your objects alone, it's hard to conceptualize what an answer actually is / means for someone who hasn't even attempted the question yet. Seeing what exactly you're updating in an answer may help clarify that. – J.D. Jul 19 '22 at 12:27

0 Answers0