I'm building a forum application using the Django web framework but I'm not sure how to design the entity relationship diagram when it comes to the Post model. Since one Post can have many replies, should I model the replies as Post objects so that there is a 1 to many relationship on the same model(Post model in this case) like this: enter image description here

Or should I make a seperate ReplyPost model and create a 1 to many relationship between Post and ReplyPost and 1 to many relationship between ReplyPost and itself(because a reply can have other replies to it...): enter image description here

Any feedback would be appreciated...

New contributor
flyingfishcattle is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • And what are the specific differences between a Post and a Post_Reply? Are they big enough to warrant two different entity types? – FrustratedWithFormsDesigner Apr 6 at 19:16
  • 1
    the only difference would be Post_Reply has two 1-to-many relations(reply_to_post_id & reply_to_reply_id) whille Post would only have 1. Doesn't seem like the differences are big enough to warrant two different entity types so I'm leaning towards the first option – flyingfishcattle Apr 6 at 20:35
  • why is my question downvoted? – flyingfishcattle Apr 7 at 13:47
  • I don't know, I didn't do that. – FrustratedWithFormsDesigner Apr 7 at 17:57

What do you want to achieve:

  • would you like a forum where replies are posts like any others,except that they refer to a previously existing post?

    In this case, you may want the option 1, but with only one forum_post table that is associated with itself. This model organises the posts as a tree (or a forest of trees if you consider each post that is not a reply to be the start of a new tree)

  • would you like a forum with posts, and replies which are of different nature (e.g. StackOverflow questions vs answers) ?

    In this case, you may want option 2, but with only one forum_reply_post table associated with itself (in addition to being already associated with forum_post). You would then be able to easily handle posts and replies in different manner and with different information. In this case each post starts a tree.

  • there’s third choice that you did not present: flatten the replies. This means that each reply is a reply only to a post. Typically, you’d show them chronologically under the post, rather than having to combine a chronological and relational presentation, which can make hard to find the latest contributions.

    In this case you’d do as in the previous bullet, but remove the self-association for the replies.

  • Yes, since I'm building a discussion forum I think option 1 would be the best option as it simplifies the design. Also, I have forum_category and forum_thread tables where Category is linked 1-to-many with Thread and Thread is linked 1-to-many with Post. Since there can only be 1 starting Post for each Thread(all other Posts in the Thread would be reply Posts), the "forest of trees" structure you described should be eliminated right? – flyingfishcattle Apr 7 at 18:58
  • @flyingfishcattle yes, the thread is this different thing that will make the forest (each post would be assigned to a thread) The option 1 would then be a suitable approach, since within a thread all messages are similar – Christophe Apr 7 at 20:23
  • thanks for the help! – flyingfishcattle Apr 7 at 20:27

Your Answer

flyingfishcattle is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.