In a StackOverflow clone, what relationship should a Comments table have to Questions and Answers?

前端 未结 6 1964
盖世英雄少女心
盖世英雄少女心 2020-11-30 06:14

In an application similar to StackOverflow that I am building, I am trying to decide what relationship my Questions, Answers and Comments

6条回答
  •  生来不讨喜
    2020-11-30 06:48

    You would need two domain tables that bring the relationships together CommentsForQuestions and CommentsForAnswers. Basically you're going to need to create 5 tables for this purpose:

    Questions
    Answers
    Comments
    CommentsForQuestions (relates comments to questions)
    CommentsForAnswers (relates comments to answers)
    

    The one problem this has is that it's inferior to the posts idea because referential integrity isn't as strong. I can garuntee that CommentsForQuestions connects to a comment and a question, but I can't prevent both a question and an answer from connecting to the same comment.

提交回复
热议问题