Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Mass Assign Then Edit Individually
    primarykey
    data
    text
    <p>Background: I have an application with athletes, each of these athletes (Athlete model) can be assigned workouts (Workout model, workout_assignment through model).</p> <p>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?</p> <p>Thank you for any advice you can give!</p> <p>Schema:</p> <pre><code> create_table "athletes", :force =&gt; 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 =&gt; 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 =&gt; 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 =&gt; 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 </code></pre> <p>Model Associations:</p> <pre><code>class Athlete &lt; ActiveRecord::Base belongs_to :coach has_many :workouts, :through =&gt; :workout_assignments end class Workout &lt; ActiveRecord::Base has_many :athletes, :through =&gt; :workout_assignments belongs_to :category end class WorkoutAssignment &lt; ActiveRecord::Base belongs_to :workout belongs_to :athlete end class Coach &lt; ActiveRecord::Base has_many :athletes has_many :workouts end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload