I have a quiz application. Which follows a normal pattern of database development
Quiz –> QuizQuestions –> QuizQuestionChoices
QuizAttempt –> QuizAttemptAnswer
In quiz_attempt_answers I store the answer as a string instead of a reference to QuizQuestionChoices for the following reason.
- If the question gets deleted from the quiz (maybe it the quiz gets revised), we don’t want to lose what they put in.
- If the choices get changed or rearranged, we want to have the answer they chose
Are these valid reasons for NOT using a foreign key for the answer?
I would continue with your approach but store the association as well.
So…
That way if a QuizQuestionChoice is deleted the foreign_key is set to null AND you still have their actual answer.
There are cases where you may even store the original question with the answer. In case somebody changes the wording which unintentionally changes the meaning of it.