0

这是由此处另一个问题的后果引起的一个问题:拥有两个单独的用户表还是一个更好?

假设我有两种类型的用户,作者和读者,每个都存储在关系表中,键控到主 Accounts 表,如下所示:

TABLE Accounts {
    id
    email
    password
    salt
    created
    modified
}

TABLE reader {
    id
    user_id
    ...
}

TABLE author {
    id
    user_id
    ...
}

当作者发布博客时,我应该使用 Authors 表中的唯一 id 还是 Accounts 表中的唯一 id 标记博客?读者评论也是如此 - 我应该使用读者表唯一 ID 还是帐户表唯一 ID 标记评论?

所以,基本上要么:

TABLE Blogs {
    id
    author_id
}

或者

TABLE Blogs {
    id
    account_id
}

哪个不太可能在以后反咬一口?

4

2 回答 2

3
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

So a user can be an admin, and an author. You can find their blogs by looking for a matching blog for this user_id. If you have account type dependant fields then place them all in the "profile" table.

于 2011-09-24T19:37:57.313 回答
1

Only you can answer fully, but my gut says that the blog entries should be tagged by author. The only reason to use account conceptually would be if a non-author can create (author) a blog post. So far, with the info provided, this does not look to be the case.

Note that I also think that all authors should be users: everybody is a user, but only some users also have authorship status.

于 2011-09-24T17:11:05.563 回答