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.
Ajit (Guest)
on 2007-08-02 01: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           removed_email_address@domain.invalid 
01/08/2007 12:30
PM

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

Please advice

thanks

Ajit
Robert W. (Guest)
on 2007-08-02 03: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.
Rob B. (Guest)
on 2007-08-02 04:02
(Received via mailing list)
On Aug 1, 2007, at 7:13 PM, Robert W. 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 B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
Ajit (Guest)
on 2007-08-02 18:27
(Received via mailing list)
thank you guys..
This topic is locked and can not be replied to.