Modeling comments

2

I'm creating a comment structure similar to the #

/ p>

NOTE: I'm calling in question and answer comments since it's basically this way that the Free Market model works.

In red questions and green answers.

  • There is only one level of response for a given question.
  • A question has several answers.
  • An answer to a single question.
  • No questions for an answer.
  • Questions and answers for a single product.
  • Be able to be redirected to the comment like here in SOpt ( en.stackoverflow.com/questions/78765/problems-with-post-en-angularjs/78773?noredirect=1#comment173023_78773 )
  • What I've done:

    comments
    --------
    
    id INT AUTO_INCREMENT PRIMARY KEY,
    comment_text VARCHAR(1000) NOT NULL,,
    type INT NOT NULL,
    user_id INT NOT NULL, #chave estrangeira para usuário que postou o comentario.
    product_id INT NOT NULL, #chave estrangeira para o produto a qual os comentários se referem.
    posted_to INT #fiquei com dúvida porque uma resposta é postada para uma pergunta mas uma pergunta não é postada para ninguém.
    date_posted DATE
    
        
    asked by anonymous 22.09.2015 / 14:59

    1 answer

    3

    It seems to be all right according to the information provided. Of course the rules of what you can and can not do, how to display (including links ) will be determined by the code (even though inside the database, which I do not like) / p>

    I would only use a NULL (it looks like it was prepared for this) or value 0 in posted_to when by a question. You do not have to duplicate in this column the information that is already in product id '.

    And if I understood what type , maybe , it is not even necessary because it can be inferred by posted_to content. But I do not know if it is worth doing this economy, because in the future something may change and this is no longer possible. Of course you could solve the problem easily if is needed. We can think of YAGNI here, or try not to be too

    22.09.2015 / 15:21