追随者/以下数据库结构 [英] Followers/following database structure

查看:74
本文介绍了追随者/以下数据库结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有一个关注者/关注系统(如Twitter的).我的困境是创建数据库结构来处理谁关注谁.

My website has a followers/following system (like Twitter's). My dilemma is creating the database structure to handle who's following who.

我想到的是创建一个像这样的表:

What I came up with was creating a table like this:

 id  |  user_id  |  followers |  following
  1  |    20     |  23,58,84  |  11,156,27
  2  |    21     |  72,35,14  |  6,98,44,12
 ... |   ...     |    ...     |     ...

基本上,我在考虑每个用户在其关注者和关注对象上都有一行带有列的行.追随者和他们追随的人的用户ID用逗号分隔.

Basically, I was thinking that each user would have a row with columns for their followers and the users they're following. The followers and people they're following would have their user id's separated by commas.

这是一种有效的处理方法吗?如果没有,最好的选择是什么?

Is this an effective way of handling it? If not, what's the best alternative?

推荐答案

那是最糟糕的方法.这是反对规范化的.有2个单独的表.用户和User_Followers.用户将存储用户信息. User_Followers将如下所示:

That's the worst way to do it. It's against normalization. Have 2 seperate tables. Users and User_Followers. Users will store user information. User_Followers will be like this:

id | user_id | follower_id
1  | 20      | 45
2  | 20      | 53
3  | 32      | 20

User_Id和Follower_Id将是引用Users表中ID列的外键.

User_Id and Follower_Id's will be foreign keys referring the Id column in the Users table.

这篇关于追随者/以下数据库结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆