I had a question about the best way to handle this type of data.
In my system, I will have many users and many accounts… users are able to belong to many accounts, and accounts will have many users. I’m guessing the best way to accomplish this is with three tables
users
accounts
& users_accounts
my question is, when someone signs up for a paid account… where should I store the flag that distinguishes between regular users of an account and account holders? Should there be an owner flag in the users_accounts table?
Can I assume that one account cannot have more than one user (1-to-many relation)? In that case, two tables would be sufficient:
usersaccountsWhere
accountscontain a reference to a user id. A separate relationship table would be superfluous when there is no many-to-many relation.Then the question arises: can a user have both paid and unpaid accounts? If so, the flag belongs in
accounts. Otherwise, it belongs inusers.Taking your clarification into account, your three tables design is appropriate. The answer to your question then completely depends on how you want paid accounts to work.
users.accounts.users_accounts.If every account has only one owner, then you should put a user id representing the owner in the
accountstable.