Hello,
I'm new to Rails and don't grasp yet all the possibilities with associations. Here's my problem:
I have a couple of models like apple and lemon. Then there's the model 'relation' that holds triples of relations:
subject | relation | object
apple | is sweeter than | lemon
The migration for 'relations' is this:
create_table :relations do |t| t.references :subject, :polymorphic => true t.string :relation t.references :object, :polymorphic => true t.timestamps end
this should store relations like
subject_id = 1
subject_type = apple
relation = is sweeter than
object_id = 2
object_type = lemon
In reality I have more than just 2 models, so I thought I need to make the subject and object column model-agnostic by using the polymorphic option.
How would you set the associations in the model classes of apple, lemon and relation? Is the table design of relations good like this?
Thanks so much for your help!!
-Alex