Database user scenario with multiple type of user
I am designing a database for a Yii project, the scenario is a user will be ONLY one of the following type: employee, company and business owner person (i.e. the owners who manage companies and employees - super admin - I broke the many to many relationship that's why I call the table "business_owner_person"). Below is how I designed my database in MySQL:
USER
- id,
- username,
- password,
- active
COMPANY
- id,
- name,
- contact_no,
- contact_name,
- address...
- user_id (FK)
EMPLOYEE
- id,
- first_name,
- surname,
- address,
- email...
- company_id (FK)
- user_id (FK)
BUSINESS_OWNER_PERSON
- id,
- name,
- email,
- position... 开发者_Go百科
- user_id (FK)
I am just wondering if there is a better/efficient way to design this scenario so that Yii won't have the problem to fetch the correct additional informations for user.
It's difficult to make suggestions without knowing a little more about the business, but it seems like you have too much redundant information.
Splitting out the user is good, since any of these types of people can be a user. I would probably put the common information, name, email into the user field, maybe even the address and position.
Then what it looks like you want is that a user can have one or more roles, where the role controls their level of access. This could be as simple, to start out with as a role_id columns in the DB table, or it could be a separate table, user_id, role_id.
Now, all that being said, it's difficult to make suggestions without more information. Do you need to isolate users by company? Will there be a lot of companies? How many business owners are you looking at having?
精彩评论