Skip to content
Advertisement

Schema Design for a questionnaire with single or multiple choices with no right / wrong answer

Firstly, I went through tens of questions over here related to mine, but couldn’t quite find what I’m looking for, hence asking a seemingly duplicate question again.

I have a requirement for a questionnaire of about 30 fixed questions for all users which can have,

  • Single select options (Text or Text with images)
  • Multi select options (Text or Text with images)
  • Free text
  • Date fields

There is no right or wrong answer since the questions cater to a user’s preferences. I’ve been working on a postgres schema design, which looks something like this.

–Questions Table–

–Options–

—Answers—

Now, I’m not sure how best to store the options in the answers table in case of a multiselect. Do I save an array of option ids? but that would render me unable to even have a foreign key ref to the options table and might make querying difficult since I need to be able to query the question-answer pairs for all questions by an individual user, this array wouldn’t help me populate the options he chose. Please help me figure out the best way to store this.

Advertisement

Answer

My model would probably look something like this…Rich

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement