Help with associating a couple of models

Here are my tables

patients
id name
1 Bob
2 Carol
3 Ted
4 Reggie

families
family_id patient_id
1 1
1 2
2 3
2 4

How do I structure the model associations so that I can
@patient.family.patient[0].name?

Make sense?

Bo Pritchard wrote in post #971530:

Here are my tables

patients
id name
1 Bob
2 Carol
3 Ted
4 Reggie

families
family_id patient_id
1 1
1 2
2 3
2 4

How do I structure the model associations so that I can
@patient.family.patient[0].name?

By writing that method chain, you’ve just about answered your own
question. Try it!

Make sense?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 30 December 2010 20:21, Bo [email protected] wrote:

family_id patient_id
1 1
1 2
2 3
2 4

How do I structure the model associations so that I can
@patient.family.patient[0].name?

I don’t think you have the tables quite right.
I think you need Patient belongs_to family (so patients table will
have family_id field) and family has_many patients. Family needs only
id field (plus other stuff I assume).

Then you can use @patient.family.patients[0].name. Note patients is
plural here.

Colin