0

I'm creating a mini-social network to a unique niche. Since I came across several problems in modeling, but what takes pisses me is the relationship with followers. Basically it will have a model like the followers of Twitter; if you can follow someone and that person does not follow you. I will share my modeling with you so they can see if it's something right thing to do. example:

tbl_users

tbl_relationship -> users1_id, users2_id, reciprocal: boolean

The idea is if User X follows User Y the relationship will be created, and if the User Y return the user will receive reciprocal field TRUE. So would not generate redundancy in the database.

This thinking is correct? I got to see several examples by Google and all were leading to redundancies of data.

I'm doing this in PostgreSQL and Rails 4.

  • 1
    Exact copy of http://stackoverflow.com/q/3397920/216513 ? – nathanvda Aug 03 '15 at 23:50
  • Yes, but maybe I have found a mistake in that modeling and mine. If the User X start following the User Y, and User Y to start following the User X, and suddenly the X user stop following the user Y ... the relationship will be deleted, so you have to have two fields. Correct? – Daniel Bastos Aug 04 '15 at 04:29
  • 1
    In my answer to that question the relationship is uni-directional, which is as it should be imho. This means: two records if two people follow each other. This is the easiest to maintain and to query. If you have a "reciprocal" relationship, how do you define the "direction" (add a type: X follows Y, Y follows X, reciprocal), and then how do you find all followers, and following, ... definitely possible, but a lot harder. – nathanvda Aug 04 '15 at 09:09
  • You mean that if the creator of the relationship undo the relationship, is to delete and recreate? – Daniel Bastos Aug 04 '15 at 15:45

0 Answers0