这个问题是由另一个问题的结果引起的:Is it better to have two separate user tables or one?
假设我有两种类型的用户,即作者和读者,每种类型的用户存储在关系表中,这些关系表键入如下主帐户表:
TABLE Accounts {
id
email
password
salt
created
modified
}
TABLE reader {
id
user_id
...
}
TABLE author {
id
user_id
...
}
当作者发布博客时,我应该使用“作者”表中的唯一ID还是“帐户”表中的唯一ID标记博客?读者注释也是如此-我应该用Reader表的唯一ID或Account表的唯一ID标记注释吗?
因此,基本上可以:
TABLE Blogs {
id
author_id
}
要么
TABLE Blogs {
id
account_id
}
以后哪一种咬的可能性较小?
最佳答案
TABLE user {
id
email
password
salt
created
modified
}
TABLE profile {
user_id
age
favorite_movie
... other useless stuff...
}
TABLE user_role {
user_id
role_id
}
TABLE role {
id
name (author, admin, user, subscriber, etc...)
}
TABLE blog {
id
user_id
title
text
...etc...
}
user HASMANY role
user HASONE profile
user HASONE blog
因此,用户可以是管理员,也可以是作者。您可以通过以下方式找到他们的博客:
查找与此user_id匹配的博客。如果您具有帐户类型相关字段
然后将它们全部放在“配置文件”表中。