Background: I have an application with athletes, each of these athletes (Athlete model) can be assigned workouts (Workout model, workout_assignment through model).
Problem: At first I thought that using a through connection with athletes having many workouts through workout_assignment and workouts having many athletes through workout_assignment would work fine for me. If I did it this way however, if I assigned a workout to 50 athletes, they would all be referencing the same workout record. I want a coach (the person who assigns workouts) to be able to assign the same workout to 50 athletes but then be able to change them one by one if he wishes (customize for the athletes). Does anyone have advice for me on how to approach this? Do I need to create 50 copies of the workout and assign each to a user, do I really need the workout_assignment through model then if I have separate workouts?
Thank you for any advice you can give!
Schema:
create_table "athletes", :force => true do |t|
t.string "name"
t.string "username"
t.string "password"
t.string "sport"
t.text "notes"
t.integer "coach_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
end
create_table "coaches", :force => true do |t|
t.string "name"
t.string "username"
t.string "password"
t.string "address"
t.string "city"
t.string "state"
t.string "zipcode"
t.string "phone"
t.string "sports"
t.integer "experience"
t.datetime "created_at"
t.datetime "updated_at"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
end
create_table "workout_assignments", :force => true do |t|
t.integer "athlete_id"
t.integer "workout_id"
t.date "date_assigned"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "workouts", :force => true do |t|
t.string "name"
t.string "type"
t.integer "coach_id"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "category_id"
end
Model Associations:
class Athlete < ActiveRecord::Base
belongs_to :coach
has_many :workouts, :through => :workout_assignments
end
class Workout < ActiveRecord::Base
has_many :athletes, :through => :workout_assignments
belongs_to :category
end
class WorkoutAssignment < ActiveRecord::Base
belongs_to :workout
belongs_to :athlete
end
class Coach < ActiveRecord::Base
has_many :athletes
has_many :workouts
end