How do I structure a database for multiple companies and if those companies have multiple branches?
Can you elaborate a little more in detail?
Usually this is done by creating additional field in users table with a boolean value to differentiate between admin/user.
In your case it will need much more that. So, the more details you provide, the easier it is to suggest.
Each company will have multiple offices.
So let’s say there are 12 offices under one company. I want to show employees of the company only the data that corresponds to the office they are in.
Company
/
Offices
/
Data unique to company and office
The part I’m struggling with is structuring my database to handle multiple companies with multiple branches.
@julianvcruz11 Ok, here’s the approach you could take.
3 Different Tables:
- Company
- Staff (Users) - Since they’ll log in to the platform
- Branches
- Company - Branches [One - Many Relationship], since there are multiple branches to each company.
- Branch - Staff [One - Many Relationship], since there are multiple staff in each branch
- Company - Staff [One - Many Relationship], since there are multiple staff in each company
Example:
- Show list of Branches to a Company, will use the first relationship and narrows down to branches belonging to the company
- Show staff belonging to a branch will use second relationship
- Show staff belonging to a company will use third relationship
Going to your Query above:
So let’s say there are 12 offices under one company. I want to show employees of the company only the data that corresponds to the office they are in.
Ans: Show a list data to the staff filtered by the company & branch he/she belongs to
Hope this helps, let me know if you have further questions.
Yes this helps. Then I should only make data unique to the branches after that.
Thank you.