So I have a HTML form where users can answer single-choice questions either by checkboxing one of the three preset responses, or writing a custom answer of their own.
While this is obviously a many-to-many relationship, I still cannot find a proper way to design database tables so as to handle both types (TEXT and BOOLEAN). My current quick-and-dirty solution is to hard-code a specific choice_id in the junction table for custom answers. I’m looking for a better pattern for this.
Have the following tables:
Table 1:
QuestionTable 2:
Question ResponseTable 3:
Question Response TypeTable 4:
Question Response DetailsWhen the following tables are populated you will have a structure that holds the question, the response of the question (text or boolean).
You could then filter on this to see only text based answers, for example:
Where 1 is a Text based answer and 2 is a Boolean based answer (From the Question Response Type Table)