作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个类似 Twitter 的关注/关注系统。表格设计是这样的 -
leader_id | following_id | is_mutual
1 | 2 | 1 // Mutually follow each other
2 | 1 | 1
1 | 3 | 0
1 | 4 | 1
4 | 1 | 1
假设我是 user_id=4
。我正在查看 user_id=1
的关注者。我会查看列表 -
2
3
4 -> me
如何确定我正在关注哪些用户或正在关注我。我想为此写一篇 Laravel Eloquent 声明。甚至 MySQL 查询也能帮助我找出执行此操作的正确方法。
最佳答案
我不会走那条路。
而是有一个一对多的订阅关系表,例如
|subscriber | subscribed_user_id
---------------------------------
|1 | 2
|1 | 3
|2 | 3
|3 | 1
甚至是 json 编码的灵活列表
|subscriber | subscribed_users
-------------------------------
|1 | {2,3}
|2 | {3}
|3 | {1}
关于MySQL : How to identify users I follow or follow me from other person's followers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59409631/
我是一名优秀的程序员,十分优秀!