Ev-genius
4 weeks ago

Linking table

Posted 4 weeks ago by Ev-genius

Hello!

Need to design a database for the training service. I made tables: Categories, exercises, programs and one linking table programs_exercises:

categories table

id | name
1  | for arms
2  | for legs
exercises table

id | category_id | name
1  |          1→ | arms-exercise-1
2  |          1→ | arms-exercise-2
3  |          1→ | arms-exercise-3
4  |          1→ | arms-exercise-4
5  |          2→ | legs-exercise-1
6  |          2→ | legs-exercise-2
7  |          2→ | legs-exercise-3
8  |          2→ | legs-exercise-4
programs table

id |	name
1  |	for mass
2  |	for strength
programs_exercises linking table

id | program_id | exercise_id
1  |         1→ | 1→ 
2  |         1→ | 2→ 
3  |         1→ | 5→ 
4  |         1→ | 1→ 
5  |         2→ | 1→ 
6  |         2→ | 3→ 
7  |         2→ | 7→ 
8  |         2→ | 8→ 

Now I need to make training programs for many days and part of day (morning, noon, evening). https://yadi.sk/i/HNgUbMVGk1ovPA

Can I add a date and part of day (morning, noon, evening) to the linking table? And then how to filter data by date when displaying programs? And how to insert data if the Date column is not the key to something?

programs_exercises linking table

id | program_id | exercise_id | date       | part_of_day
1  |         1→ | 1→          | 2020.09.25 | morning
2  |         1→ | 2→          | 2020.09.25 | morning
3  |         1→ | 5→          | 2020.09.25 | noon
4  |         1→ | 1→          | 2020.09.25 | noon
5  |         2→ | 1→          | 2020.09.25 | morning
6  |         2→ | 3→          | 2020.09.25 | noon
7  |         2→ | 7→          | 2020.09.25 | evening
8  |         2→ | 8→          | 2020.09.25 | evening

I mean that with such a request

$programs = Program::with('exercises')->get();

we will not get the date and morning/noon/evening from the link table.

Please sign in or create an account to participate in this conversation.