A
A
Analka2021-08-16 15:52:55
Database design
Analka, 2021-08-16 15:52:55

How to properly build relationships and design tables?

Hello! Need advice:

There is a table of users

Users
-id
-first_name
-last_name


company table
Company
-id
-name
-slug
-logo


There is a table of roles
Role
-id
-name


Comment table
Comment
-id
-company_id (id компании на которую отзыв)
-user_id (id пользователя кто оставил коммент)
-text


The bottom line is that a company can have several employees who can manage certain functions in the profile: admin,

manager the name of the company to which they are attached was written

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-08-16
@Analka

We need at least two more tables.
The first describes a many-to-many relationship between a company and a role. Indeed, in different companies there may be a different set of roles - somewhere there is an auditor, but somewhere not, for example ...
The second describes a many-to-many relationship between the user and the first table.
Together they define what specific role in a particular company a particular user has.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question