Answer the question
In order to leave comments, you need to log in
Work schedule for companies, how best to link a table?
Hello!
There is a Company model with information about the company.
You need to attach the work schedule to the companies on the site, as in the photo:
I understand that you need to add an additional Schedule table (with fields: day of the week, start date, end date and breaks).
What is the best way to bind Schedule to Company via manytomany or foreign key?
Answer the question
In order to leave comments, you need to log in
Here you need to proceed from the task (it is not completely clear on the issue).
If you have one or more schedules for one company, then through Foreign Key. In this case, all companies will have their own copies of schedules.
And if you need to make it so that several companies should have a common schedule, then ... also Foreign Key in the company model :)
ManyToMany is a many-to-many relationship, i.e. when “you don’t understand anything at all” and any company can have either its own schedule, or someone else’s, or both.
... if I understand the question correctly, of course)
The main disadvantage of using m2m in this situation is that changing the schedule for one company, it will change for others associated with this record.
Here you need to think about the essence of objects. The schedule is not self-sufficient, it depends entirely on the company.
I think it would not even be criminal to make a Schedule model with 14 fields of the day_week_start/end type.
Or, as you wanted, the Schedule table with the fields day_of the week, company, start, end. At the same time, with control over the uniqueness of the day_of the week <==> company.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question