Ruby on Rails Thursday, December 30, 2010

On 30 December 2010 20:21, Bo <bo@4peculiarpeople.com> wrote:
> 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?

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment