0

I'm trying to design an ER diagram of Reddit as part of a project.

I need help mainly for the post and comments.

The way I see it, posts and comments have several attributes and relation in common, so I tried to create a parent entity called Thread as an EER diagram. A comment links to another comment or to a post. Hence the relation of 'points to' is connected to the Thread entity.

Other relations that are common to comment and post are relation with Report, relation with Award. etc

Another option would be to separate Post and Comment and get rid of Thread all together and make relations individually. My doubt is that, is this correct? or is this the best way we could do it? enter image description here

enter image description here

Updated Diagram: enter image description here

  • The updated diagram look great but, the relation between ``Vote`` and ``User`` should be : one ``User`` have Zero or Many ``Vote``, one ``Vote`` have one ``User``. The symbols you are using there on the ``Vote`` side is wrong. It should be One (and only one). https://stackoverflow.com/a/47439158/6503197 (I think this post is really helpfull to keep in mind different cardinality) – vincent PHILIPPE Sep 22 '20 at 12:30

1 Answers1

2

It look like that in your diagram nothing rely a Comment to a Post. I mean nothing add the relation that : Many Comment have One Post, One Post have Many Comment. Because I suppose that a Comment only exist on a Post. If the Post get deleted, all Comment get deleted too. Maybe you should rely them with this ManyToOne, OneToMany relation.

I think that the Inheritance you are using doesn't specify the relation which I mention above. You actually using inheritance more or less just as a provider of common properties. I'm not sure this is a good thing, because actually Post will inherit of the relation of points to.

By using this inheritance you say that :

  • One Post, or one Comment is related to OneToMany Comment (<== you should use Zero or Many);

Maybe to keep thing simple you should do something like :

  • Post ZeroToMany Comment (Zero or many)
  • Comment OneToOne Post (one and only one)
  • Comment ZeroToMany Comment (Self reference)
  • Comment ZeroToMany Comment (Self reference)

I try to illustrate what I'm thinking about :

enter image description here

Also, you need this VOTE entity to keep track of which user have upvote or downvote a contribution.

I'd caution that I don't really know Reddit so I relied on the stack overflow post and comment system.

halfer
  • 18,701
  • 13
  • 79
  • 158
vincent PHILIPPE
  • 779
  • 3
  • 20
  • Thank you so much for your reply. Actually, the 'points to' relation have to be one-to-one instead of what the diagram depicts. What that should imply is that every comment entry would have a foreign key of the thread(either a post or a comment) to point to. as is the comment will exist for a post or another comment. Hence, the post would also inherit this relation. – Safeer Khan Sep 22 '20 at 11:11
  • I think I need to look at how reddit work. If I'm understanding, you say that each comment is rely to one thread so this forms something like a comment chain. Ok I see ! But still you must use add a ``Vote`` entity to track ``User`` down/upvote. – vincent PHILIPPE Sep 22 '20 at 12:01
  • The interrest of having a relation between ``Comment`` and ``Post`` as depicts in my little diagram would be to be able to count the total number of comment very easily, instead of looking at every comment, and all of their subcomment, ect... You see what I mean ? I think it would'nt be such a bad idea to keep info about what is the `original` post related to any comment. This is just my opinion. – vincent PHILIPPE Sep 22 '20 at 12:14
  • 1
    yes, I guess this has become like a linked list. so like all operations in the linked list, here also it would be O(N). so Counting, searching, deleting, would all be of O(N). Thanks for pointing out the Vote as an entity, I guess that's a very silly mistake on my part. could you please check the updated image I've added in the post. Thanks again! – Safeer Khan Sep 22 '20 at 12:24