I am writing a site that tracks workouts. Thus far I have the following models: User -> UserExercise (the workout) <- Exercise Workouts have two types of exercises -- time based (run 4 miles) and weight based (bench press 225 lbs 10 times in 3 sets) to account for this I have two 1 to 1 tables that correspond to UserExercise. WeightBased -> UserExercise <- TimeBased There will be two different forms to update an exercise depending on what type of exercise this is. This seems much cleaner than a UserExercise table that has all the fields, only some of which are used. Here are my fields: UserExercise ------------ id user_id exercise_id WeightBased ----------- user_exercise_id weight (int) reps sets TimeBased user_exercise_id reps rep_distance seconds_elapsed the first problem is that microsoft access (just for testing, ok) requires both 1-to-1 tables to be updated -- this makes no sense, but i might be missing something and want to check. Also, is it rails practice to set the primary key of a one-to-one table to be the primary key of the parent table? thanks for any advice. tim -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think polymorphic relationship is the right solution for ur case. Read the rails docs and wiki for more info. Http://www.rubyplus.org Free Ruby & Rails screencasts On Mar 15, 2008, at 7:18 PM, Tim Booher <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > wrote:> > I am writing a site that tracks workouts. Thus far I have the > following > models: > > User -> UserExercise (the workout) <- Exercise > > Workouts have two types of exercises -- time based (run 4 miles) and > weight based (bench press 225 lbs 10 times in 3 sets) > > to account for this I have two 1 to 1 tables that correspond to > UserExercise. > > WeightBased -> UserExercise <- TimeBased > > There will be two different forms to update an exercise depending on > what type of exercise this is. > > This seems much cleaner than a UserExercise table that has all the > fields, only some of which are used. > > Here are my fields: > UserExercise > ------------ > id > user_id > exercise_id > > WeightBased > ----------- > user_exercise_id > weight (int) > reps > sets > > TimeBased > user_exercise_id > reps > rep_distance > seconds_elapsed > > the first problem is that microsoft access (just for testing, ok) > requires both 1-to-1 tables to be updated -- this makes no sense, > but i > might be missing something and want to check. Also, is it rails > practice > to set the primary key of a one-to-one table to be the primary key of > the parent table? > > thanks for any advice. > > tim > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think you might be right, but i am not completely sure polymorphic is best here. If I did use polymorphic my implementation would look like: User ----> UserExercise <---- Exercise | | | exercise_interface | | | has_one | has_one | :as => exercise_interface | :as => exercise_interface | | TimeBased WeightBased - time_elapsed - reps - distance - weight This would work well, except my exercise_type field does not belong in UserExercise, but in Exercise, the table that has the actual descriptions, etc of the exercise. UserExercise records a specific implementation of an exercise (i.e. the data. so naturally, it seems ugly to record the exercise type in UserExercise. I have attached my ER diagram (written in access just to play around with these ideas before i implement in mysql) but this is great stuff, i am really am learning how this works. thanks for any help. best, tim Attachments: http://www.ruby-forum.com/attachment/1604/UserExercise.JPG -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
oops -- bad tabbing there -- hope this is easier to follow User ----> UserExercise <---- Exercise | | | exercise_interface | | | has_one | has_one | :as => exercise_interface | :as => exercise_interface | | TimeBased WeightBased - time_elapsed - reps - distance - weight Tim Booher wrote:> > > I think you might be right, but i am not completely sure polymorphic is > best here. If I did use polymorphic my implementation would look like: > > User ----> UserExercise <---- Exercise > | > | > | > exercise_interface > | | > | has_one | has_one > | :as => exercise_interface | :as => exercise_interface > | | > TimeBased WeightBased > - time_elapsed - reps > - distance - weight > > This would work well, except my exercise_type field does not belong in > UserExercise, but in Exercise, the table that has the actual > descriptions, etc of the exercise. UserExercise records a specific > implementation of an exercise (i.e. the data. so naturally, it seems > ugly to record the exercise type in UserExercise. > > I have attached my ER diagram (written in access just to play around > with these ideas before i implement in mysql) > > but this is great stuff, i am really am learning how this works. thanks > for any help. > > best, > > tim-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---