Reputation: 10538
I'm writing a simple "Facebook Wall" type feature where a user can post on another person's wall and people can simply reply to that Wall post, or post a new wall post. Users cannot reply to a reply, you may only reply to the original wall post (just like facebook)
My original mySQL db schema that I had thought of goes like this:
post_id (pk) post_text (char) date_posted (datetime) is_parent (bool) parent_id (id of parent)
How it works:
If someone posts a new wall post, is_parent will be set to 1, and parent_id will be set to null.
If someone posts a reply to that post, is_parent will be 0, and parent_id will be set to the ID of the parent post.
My Questions
Upvotes: 0
Views: 554
Reputation: 181
Upvotes: 0
Reputation: 932
First of all. I don't think you need two field for the same purpose. parent_id is enough in this case. When you have post_id set auto-increament. The first assigned value will be 1, so parent_id=0 will never happen. You can assume when parent_id=0 it is a first level post.
It would be better to use one single query for all replies.
Upvotes: 1