Hi Bubbler’s, I’m hoping someone can help me with the below issue.
I’m building an app to help me track my workouts and I’d like the ability to repeat a previously completed workout.
Database set up:
Workouts
Containing field:
“List of Exercises” containing all the exercises in the workout.
Workout Exercises
Containing fields:
“List of sets” containing all the Sets in this Exercise
“Workout” containing the Workout this exercise belongs to.
Workout Sets
Containing field:
“Workout exercise” containing the Exercise this set belongs to.
I’ve attempted to achieve this by creating a new Workout and copying all Workout Exercises and all Workout Sets.
The problem I’m having is then placing the sets and exercises in their relevant data fields?
Have I gone the right way about this or is there a much simpler way?
Can a Workout Exercise belong to more than one Workout? It seems from your dB setup that the answer is no, but given that you say you want to be able to create new workouts from old ones, it seems to me that you may want to reconsider this.
Assuming that you want to keep your setup as it is then let’s say you want to create workout B from workout A, you could do the following:
Create a new workout - workout B
For each exercise in workout A :
2.1 Create a new exercise and set its workout to workout B
2.2 Add the created exercise to workout B’s list of Exercises
2.3 For each set in the original exercise, create a new set and set its exercise to the exercise created in 2.1 then add this new set to the exercise’s list of sets
If on the other hand you set your db up (such that a Workout Exercise can belong to more than one Workout) then things become more simple. You could just Create a new workout B and set its List of Exercises to the same as workout A’s.