博客和评论使用哪个唯一 ID?

发布于 2024-12-06 05:24:46 字数 683 浏览 0 评论 0原文

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

假设我有两种类型的用户,一个作者和一个读者,每个用户都存储在与主帐户表相关的关系表中,如下所示

TABLE Accounts {
    id
    email
    password
    salt
    created
    modified
}

TABLE reader {
    id
    user_id
    ...
}

TABLE author {
    id
    user_id
    ...
}

:作者帖子博客,我应该使用作者表中的唯一 ID 还是帐户表中的唯一 ID 来标记博客?读者评论也是如此 - 我应该使用读者表唯一 ID 还是帐户表唯一 ID 来标记评论?

所以,基本上要么:

TABLE Blogs {
    id
    author_id
}

要么

TABLE Blogs {
    id
    account_id
}

哪个稍后不太可能反击?

This is a question that arose from the consequences of another question here: Is it better to have two separate user tables or one?

Assuming I have two types of users, an Author and a Reader, each stored in relational tables keyed to a main Accounts table like so:

TABLE Accounts {
    id
    email
    password
    salt
    created
    modified
}

TABLE reader {
    id
    user_id
    ...
}

TABLE author {
    id
    user_id
    ...
}

When an Author posts a blog, should I tag the blog with the unique id from the Authors table, or the unique id from the Accounts table? Same goes with reader comments - should I tag the comment with the Reader table unique id, or the Account table unique id?

So, basically either:

TABLE Blogs {
    id
    author_id
}

OR

TABLE Blogs {
    id
    account_id
}

Which is less likely to bite back later on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋意浓 2024-12-13 05:24:46
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 匹配的博客。如果您有帐户类型相关字段
然后将它们全部放入“配置文件”表中。

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.

挽容 2024-12-13 05:24:46

只有你才能完整回答,但我的直觉告诉我博客条目应该由作者标记。从概念上讲,使用帐户的唯一原因是非作者可以创建(作者)博客文章。到目前为止,根据所提供的信息,情况似乎并非如此。

请注意,我还认为所有作者都应该是用户:每个人都是用户,但只有某些用户也具有作者身份。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文