相关疑难解决方法(0)

是否有一种优雅的方式来存储双重关系(即用户1和用户2是朋友)

我本月在两个不同的工作中遇到了同样的问题:

Version 1: User 1 & User 2 are friends
Version 2: Axis 1 & Axis 2 when graphed should have the quadrants colored...
Run Code Online (Sandbox Code Playgroud)

问题是,我没有看到使用RDBMS来存储和查询此信息的优雅方式.

有两种明显的方法:

方法1:

store the information twice (i.e. two db rows rows per relationship):
u1, u2, true 
u2, u1, true
u..n, u..i, true
u..i, u..n, true

have rules to always look for the inverse on updates: 
on read, no management needed
on create, create inverse
on delete, delete inverse
on update, update inverse

Advantage:    management logic …
Run Code Online (Sandbox Code Playgroud)

database database-design bit-manipulation bitmask social-networking

5
推荐指数
1
解决办法
382
查看次数