Reputation: 16017
I need some help with this table structure, because it turned out to be more complex than I expected. I am creating comments and I can't figure out what table structure I should use.
I have multiple tables on which users can post comments to ( like posts, photos etc ), which calls for 1 identifier. Each item has its own id - second identifier. And each comment has its own id - third identifier. The way I see it is to have 3 columns, respectively id, item_id and table, but you guys are telling me that saving tables in tables is not good. I can't think of any other structure. That may be due to the fact that once our brain is stuck with an idea it can't get unstuck, or maybe just because I'm dumb. Anyway I'd really like some help out here, it'd be great if I could get this goin for me.
Upvotes: 0
Views: 63
Reputation: 3641
you can do like this:
comments :
comment_id - primary key
comment - actual comment (mandatory)
user_id - user who post comments. (mandatory)
post_id - post id on which user comments (optional)
photo_id - user photo id on which user commented (optional)
etc as required.... then status, created_by, create_date, updated_by, updated_by
Either post_id or photo_id will be mandatory / their and accordingly you can go
this approach is good one as if you required to add comment for any thing else i.e. videos then just add video_id
Upvotes: 1