Question

I'm developing a simple iOS application with the following database setup. There is an Athlete entity which has a many to many relationship with Workout. Workout has a to many relationship with Workout Scores. Athlete<<->>Workout<->>Workout_Scores. I think i've set up my model incorrectly though. I was thinking athletes can share workouts (e.g. multiple athletes have the same workout object), or, an exercise may be exclusive to one person. However, the exercise score is strictly for one athlete, not shared. You can have up to 1 score for each workout. 2 athletes can have the same workout, but their score should be separate. Did I set up my model correctly? Should the score entity be related to athlete, not workout?

Was it helpful?

Solution

It sounds like you want to use Workout_Scores as a sort of join table (although that of terminology isn't appropriate for an object-graph framework like CoreData). Your Workout_Scores entity should have two to-one relationships to Athlete and Workout. Athlete should have a to-many relationship to Workout_Score (an athlete may have many workout scores), and Workout should have a to-many relationship to WorkoutScore (a workout may have many workout scores that originated from a single or from many different athletes).

Here's what I propose for your data model:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top