Database Design Problem

I am creating a database for an application where the user can comment on images and videos.

Should I keep separate tables for comments such as (Picture_comments and videos_comments)
OR
should I keep separate tables for comments and other mapping tables such as (picture_comment_mapping and video_comment_mapping).

Which one is better and why?

Details
Approach 1:

user
     id
     name

Picture
     id
     link
video
     id
     link

comment_video
     id
     user_id
     video_id
     comment
comment_picture
     id
     user_id
     picture_id
     comment

Approach 2:

user
     id
     name

picture
     id
     link
video
     id
     link

comment
     id
     user_id
     comment

comment_picture_mapping
     id
     comment_id
     picture_id
comment_video_mapping
     id
     comment_id
     video_id

Which one is better and why?

+3
source share
4 answers

"" . , . - -

enum MimeType {
    PICTURE, VIDEO;
}

class Comment {
    @ManyToONe
    private User user;
    @Enumerated
    private MimeType mimeType;
}

? , mime. diff, .

+1

2, , " "

+2

, . 2 , , , . , , , mime. .

Comment
 id
 user_id
 comment_text
 comment_type
 linked_object_id

CommentObect
  id
  type
  object
+1

( , User).

2 , . , ?

{one-to-many} {--} ( )

0

All Articles