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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 December 2010 20:21, Bo <bo-6mZqNGbT+O+nGse9nuGS3EEOCMrvLtNR@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.