开发者

Which unique id to use for blogs and comments?

开发者 https://www.devze.com 2023-04-08 17:00 出处:网络
This is a question that arose from the consequences of another question here: Is it better to have two separate user tables or one?

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 table开发者_如何学运维s 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消