Best way to define assocations

I think this is an easy question, but i just don’t know the best way to
do this.

I have the following tables:

  • Exercises
  • Biking_details
  • Running_details.

as you can see i have 2 kinds of Excercises: running and biking

so i could do this:

has_one :biking_details
has_one :running detail

belongs_to :exercise

belongs_to :exercise.

of course this could work, but these models would allow that an exercise
would have both running and bking details, which is not possible

when i would like to generate a list of exercisess with a column
“exercise type”, i would have to loop though a the list of exercises and
for each record check if there is biking detail OR a running detail,
generating a lot of queries

i could solve this by adding a field exercise_type to the exercises
table, but wouldn’t this be kind of redundant?

so now i am having troubles to decide what to do

who can give me some insight?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs