0
votes

I'm creating my first web app as an assignment. I am writing my project proposal and part of the proposal is to create a schema.

The app concept is simple, it's creating a workout log, where users can create, edit and delete workouts all kept in an organized log.

I am having trouble thinking about the best way to structure the database so when a user wants to fetch a specific workout, it comes with all exercises and their results.

So far I've come up with this layout. I guess workouts.exercises.results would gather the correct information, but I wanted to know if their was a tidier way to organize this data as it is my first time and I am trying to create this using best practices.

workouts

column name

id
name
user_id
updated_at

exercises

column name

id
name
workout_id
updated_at

results

column name

id
exercise_id
workout_id
sets
reps
duration
updated_at

1

1 Answers

1
votes

As per my understanding, Workouts has many exercises, Exercise has one Result.

If yes, then you don't need workout id in result table.

For fetching the records by workout, use the following code:

w = Workout.find(workout_id)
w.exercises.each do |e|
   puts "Exercise=#{e.name} and result = #{e.result}}
end