Rails association for a direct association and a 'through' association

70 Views Asked by At

I'm trying to get my head around the best association strategy for the following type of scenario in rails:

  • An owner has many samples (these can be individual or as a member of a sample set).
  • An owner has many sample sets.
  • A sample set has many samples.

Therefore how best to set up my models so that I can add add a sample to an owner either directly or through adding the sample to a sample set and then adding the sample set to the owner? I don't think I want to use a 'has_many through' here as samples will not always be part of a sample set. And I would want one encompassing call to include both owner.samplesets.samples and owner.samples.

Does anyone have advice on which of the many types of associations I should be investigating for this, or if I need any helpers for this?

Regards Gerry

0

There are 0 best solutions below