how to represent symmetric many to many relationship

后端 未结 5 932
盖世英雄少女心
盖世英雄少女心 2020-12-06 18:05

suppose i have a entity called USER and a relationship FRIENDSHIP exist between two USERs SO for that i have a table \'USER\' and a relationship table \'FRIENDSHIP\'

5条回答
  •  萌比男神i
    2020-12-06 18:36

    The obvious solution is to store just 1 record per each pair of friends. However, it makes harder to maintain uniqueness; all queries for getting/updating/removing friend relationship become more complex compared to "redundant" solution. Also, the solution with 2 records allows you maintain friends requests (E.g., UserA asks UserB to be a friend. UserB can confirm or reject this request). So I'd say redundancy is perfectly valid in this case.

提交回复
热议问题