Forum: Ruby on Rails concept for foreign key

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1071f217bcdd54ab8ee844489eead96?d=identicon&s=25 Ajit (Guest)
on 2007-08-01 23:46
(Received via mailing list)
Hi

I have a table named "appointments" and it has a field "patient_id".
And i have "patients" table as well, with all the patient's personal
info

now i want to display all the appointments for today with patients
details. E.g

Name        Phone      Email                            Appointment
Time
ABC          123           abc@xyz.com               01/08/2007 12:30
PM

I have appointments Controller, helper, model but nothing patient so
far.

Please advice

thanks

Ajit
21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-08-02 01:14
(Received via mailing list)
A patient has many appointments. An appointment belongs to patient.
Appointment.patient.first_name.

It's really about that easy.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-08-02 02:02
(Received via mailing list)
On Aug 1, 2007, at 7:13 PM, Robert Walker wrote:
>> info
>> I have appointments Controller, helper, model but nothing patient so
>> far.
>>
>> Please advice
>>
>> thanks
>>
>> Ajit

Something in your controller like:

@appointments = Appointment.scheduled_for(Date.today)

and in your model

class Appointment
   def self.scheduled_for(day)
     find(:all, :include => :patient,
          :conditions => { :appointment_time =>
day.to_time...day.to_time.tomorrow },
          :order => 'appointments.appointment_time, patients.last_name')
   end
end

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
C1071f217bcdd54ab8ee844489eead96?d=identicon&s=25 Ajit (Guest)
on 2007-08-02 16:27
(Received via mailing list)
thank you guys..
This topic is locked and can not be replied to.