What Db structure should be used with 2 identical comment tables for two different parent tables

This is a tricky design issue for the application I'm working on. I have two different elements in the application that will use comments. What, but I can’t decide how to create my database.

There are two possibilities. The first is a different comment table for each table that requires comments (normalized path):

movies -> movie_comments
articles -> article_comments

The second way I was thinking about is using a common comment table, and then you have a lot of two relationships for comments and relationships with movies. For instance,

comments

comments_movies (movie_id, comment_id)
comments_articles (article_id, comment_id)

What is your opinion that the best method will be and you can give a good reason that I can decide.

+3
5

comments

comments_movies (movie_id, comment_id)
comments_articles (article_id, comment_id)

, . - . ,

, - , , , :)

+4

, ( ). . ...

, . , .

, , , . , .

+1

"" , : , .

, , . , .

- . .

  • , " " ( ) , . .

  • , n:: n , CommentMovie CommentArticle.

  • Db , , :

    • , 1:: 1 Movie.PK Movie

    • , 1:: 1 Article.PK,

    • , 1:1 . PK

    • , 1:1 CommentArticle.PK(; PK , (ArticleId, CommentId)) CommentArticle. ( n:: n) .

    • , 1:1 CommentMovie.PK(; PK , (MovieId, CommentId)) CommentMovie. ( n:: n) .

+1

:

movies -> movie_comments -> comments
articles -> article_comments -> comments

, ( ).

. , , , . .

0
comment_table
-------------
comment_id (int)
object_id  (int) 
comment    (varchar(max)) 
type       (int)
--------------

object_id , , , ..

type is 1 : the comment was made for the film, type is 2 : the comment was made on the article

You can create your tables as follows.

-1
source

Source: https://habr.com/ru/post/1773527/


All Articles