具有黑名单和收藏夹列表的用户注册系统的数据模型? [英] data model for user register system with blacklist and favoritelist?

查看:86
本文介绍了具有黑名单和收藏夹列表的用户注册系统的数据模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我用户注册系统的数据模型,用户可以互相喜欢或黑名单吗?我正在寻找最好的方法,但是到目前为止,没有人很好地回答我的问题。

can someone show me data model for user register system which user can favorite or blacklist(ban) each other?i am looking for best way but no one answered my questions well until now.by best way i mean we have less join for programing.

我的用户表

uid(pk) | name | family | blah blah blah ..

我只是不知道如何设计这个我们最喜欢的黑名单加入还是更少?

i just dont know how to desgin this favorite and blacklist which we just have one join or less?

我认为这必须是一对多的关系,但是我应该如何设计呢?

i think it must be a one to many relation but how should i design this?

推荐答案

您可以使用第二个表列出黑名单和/或收藏夹

you could have a second table listing the blacklists and/or favourites


id(pk)| userid_src(fk)| userid_dst(fk)|

table id(pk) | userid_src(fk) | userid_dst(fk) | type

如果用户A将用户B列入黑名单,然后将用户A的收藏夹用户C以及用户B和C的收藏夹彼此列出,您将拥有A,其中id为1,ID为2和C id 3

If user A blacklists user B and then user A favourites user C and user B and C favourites each other you will have this where A is id 1, B id 2 and C id 3

id(pk) | userid_src(fk) | userid_dst(fk) | type
1      | 1              | 2              | blacklist
2      | 1              | 3              | favourite
3      | 2              | 3              | favourite
4      | 3              | 2              | favourite

编辑:检索每个用户的信息:

to retrieve the info of each user :

SELECT * from users
LEFT JOIN users_connections as con ON users.uid = con.userid_src
LEFT JOIN users as userCon ON userCon.uid = con.userid_dst
WHERE users.id = XXX

XXX将是您当前用户的ID 。然后,您将检索当前用户与他列入黑名单或添加为收藏夹的每个用户之间的每个连接。

XXX will be the id of your current user. You will then retrieve each connections between your current user and each user he blacklisted or added as favourite.

这篇关于具有黑名单和收藏夹列表的用户注册系统的数据模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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