A
A
Alexander Shapoval2017-08-02 06:28:40
MySQL
Alexander Shapoval, 2017-08-02 06:28:40

Do I need a user ID field in both tables?

To capture the essence of the issue, the situation is as follows.
- there are users
- there are projects created by users
- there are tasks for projects mentioned above
----------------
- users
--- id
- projects
--- id
--- id_user
--- title

- tasks
--- id
--- id_project
--- message
--- id_user (?)

--------------------
Previously working with other people's codes (in the end I adopted it for myself) I noticed that wherever the user creates something there is an id_user field , and this is understandable, but if there is an intermediate table with this field (in my case, projects) then in tasks (what would be all in feng shui) this field does not need to be added already (or is it not feng shui anymore?)
When selecting stasks, we have id_project , we can find out our cherished id_user in the projects table from it . tasks.id_project is associated with projects.id projects.id_user is associated with users.id It seems that everything is elementary, but why then create id_user in both tables, anyway, the data in these fields will be the same (in id_user), and if they are different, then these are already errors in the application.


Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2017-08-02
@sanek_os9

Feng Shui is not needed.
If you enter a user_id in tasks, then there is a non-zero probability of project.user_id and tasks.user_id being out of sync. And it will be necessary to catch this moment somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question