gpt4 book ai didi

MySQL : How to identify users I follow or follow me from other person's followers?

转载 作者:行者123 更新时间:2023-11-29 15:20:23 27 4
gpt4 key购买 nike

我正在尝试创建一个类似 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com