How to store bidirectional relationships in a RDBMS like MySQL?

前端 未结 3 1351
面向向阳花
面向向阳花 2020-12-28 08:45

Suppose I want to store relationships among the users of my application, similar to Facebook, per se.

That means if A is a friend(or some relation) of B

3条回答
  •  余生分开走
    2020-12-28 08:54

    While choosing between option 1 and option 2 in Branko Dimitrijevic's options you should consider this :

    Is the relation you're trying to design symetrical or assymetrical ?

    For example (bad example but still illustrates my point) if you're only trying to know whether both users are family or friends, then the link is symetrical. If one user is a member of the other's family then the inverse is true. Approach 2 might be considered.

    But if you want more specific information like what type of family one person is to another (is it their father, son, uncle ?) then it becomes assymetrical. If A is B's father then B is A's son/daughter. Approach 1 might become necessary.

提交回复
热议问题