Hi all, I am using Active record against a legacy schema (and I am a rails newbie). I am having trouble in getting the "belongs_to" and "has_many" relationships to work. I have the following 2 tables in the schema: PATIENT: PATIENT_ID (PK) ... ELIGIBILITY_INFORMATION: ELIGIBILITY_ID (PK) PATIENT_ID (FK) .... I have defined the following 2 classes: class Patient < ActiveRecord::Base self.primary_key = "PATIENT_ID" self.table_name = "PATIENT" has_many :eligibilities, :foreign_key => "PATIENT_ID" end class Eligibility < ActiveRecord::Base self.primary_key = "ELIGIBILITY_ID" self.table_name = "ELIGIBILITY_INFORMATION" belongs_to :patient end Here is my console output:>> p = Patient.find(''1'')....>> p.eligibilities[] In the DB eligibility_information table has several eligibility records with PATIENT_ID = ''1''. Why is the p.eligibilities collection empty then? How do i correct this? It looks like I am missing something basic here. Please help .... Thanks, Rushabh --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
has_many :eligibilities, :foreign_key => "PATIENT_ID" shouldn''t that be: has_many :eligibilities, :foreign_key => "ELIGIBILITY_ID" -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Stone wrote:> has_many :eligibilities, :foreign_key => "PATIENT_ID" > > shouldn''t that be: > > has_many :eligibilities, :foreign_key => "ELIGIBILITY_ID" >I dont think that is correct. PATIENT is the parent table. And so PATIENT_ID would be the foreign key in the ELIGIBILITY_INFORMATION table. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > I dont think that is correct. PATIENT is the parent table. And so > PATIENT_ID would be the foreign key in the ELIGIBILITY_INFORMATION > table. >Ooops. You''re right. Sorry about that... has_many :eligibility -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > has_many :eligibility >Andrew, this did not work :( --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/3/06, Rushabh <joshirushabh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > > > has_many :eligibility > > > > Andrew, this did not work :( > >Sorry to hear that, getting the same error? -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---