Use the Patient and PersonName relationship I.e. :
@person = PersonName.find_by_last_name
Then a simple @person.patient will return the patient class object since rails 
knows the relationship.  I would just include the first_name and last_name 
fields in the patient table. Having a seperate datafield to hold that little of 
info seems silly.  You could use methods within the patient class to seperate 
the first_name and last_name data instead.
Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: Lance Klusener <[email protected]>

Date: Fri, 2 Jan 2009 00:18:37 
To: <[email protected]>
Subject: [Rails] Searching for an entry in a one to one relationship



1] I had a "Patient" model which is in a one to one relationship with
the "PersonName" model

class Patient < ActiveRecord::Base
  has_one :person_name
end

class PersonName < ActiveRecord::Base
  belongs_to :patient
end

2] "person_name" has the "last_name" and "first_name" as 2 of the fields

3] I am trying to find the Patient on the basis of his last_name , how
do i go about doing this , any example's will be HIGHLY appreciated.

The way i entered the data in was first create a PersonName

@personName = PersonName.new ( :last_name => "jack" , :first_name =>
"daniels")
@patient.person_name = @personName

Thanks in advance.
-- 
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to