I am using http://guides.rubyonrails.org/ to learn ruby & rails. I have problem with joining three tables. , so I made new project as this example: http://guides.rubyonrails.org/association_basics.html#the-has_many_through-association i have three tables physicians, appointments & patients
Models:
physician.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
attr_accessible :name
end
appointment.rb
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
attr_accessible :appointment_date, :patient_id, :physician_id
end
patient.rb
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
attr_accessible :name
end
I want to display the patient name, physician name & appointment_date. how to do this. thanks in advance.