Which unique id to use for blogs and comments?

你说的曾经没有我的故事 提交于 2020-01-06 14:15:51

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7540449/which-unique-id-to-use-for-blogs-and-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!