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