Hi,
I''m very new to RoR so my question may be bit stupid.
I''m trying to create application that could serve as training log. So
I have "Trainee" who goes to a gym. What he/she does is a
"Workout" (and there is a bunch of them in list to choose from).
Now there are many Trainees in a gym at a same time having different
(or same possibly) Workout.
So I have a table with Trainees, table with Workouts and I would like
to join them in Trainings ( Trainee id_1 did Workout id_2, Trainee
id_2 did Workout id_4, both at 6 pm on 28.12.2008). One Training has
many Trainees each with different or same Workout. Trainees and
Workouts are connected together by join table with one additional
value of date and time of training.
At the beginning my idea was this
class Trainee < ActiveRecord::Base
has_many :trainings
has_many :workouts, :through => :trainings
end
class Training < ActiveRecord::Base
belongs_to :workouts
belongs_to :trainee
end
class Workouts < ActiveRecord::Base
has_many :trainings
has_many :trainees, :through => :trainings
end
But I don''t want to create new Trainee with new Workouts, both would
be more or less stable (list of Trainees and list of Workouts to
choose from). I would like to add new Training, choose date&time,
choose Trainees (one or more) and attach Workouts to them (same or
different to each) (so multiple Trainees on one Training, each Trainee
with one his own Workout).
My queries should be something like
- who did Workout_id1 with best time
- which Workouts Trainee_id2 did in last 30 days
- who attended Training on 28.12.2008
etc.
Is my association model correct ? Could I use join table directly like
this ?.
Thank you very much
Petr Ruzicka
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---