mysql structure for comments and comment replies

前端 未结 7 834
耶瑟儿~
耶瑟儿~ 2020-12-04 20:16

I\'ve been thinking about this one for quite some time now, I need a way to add replies to comments in the database but I\'m not sure how to proceed.

This is my curr

7条回答
  •  隐瞒了意图╮
    2020-12-04 20:54

    Add a parent_comment_id column to your comments table. Make it optional. When you query, you can join all child comments to each parent. As a bit of selective denormalization (slight redundancy) you can make sure topic_id is set on the child comments as well, letting you pull them all a bit easier (assuming you're going to display all child comments in the main comment thread and not via smaller ajax requests).

    Build the presentation however you need, toss the results into memcached (or a flat file, or memory... however you're caching) and you're set.

提交回复
热议问题