One-to-One relationship -- good idea?

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

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

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

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: