我正在使用http://guides.rubyonrails.org/来学习 ruby 和 rails。我在加入三个表时遇到问题。,所以我做了一个新项目作为这个例子: http: //guides.rubyonrails.org/association_basics.html#the-has_many_through-association我有三个表医生,约会和病人
楷模:
医师.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
attr_accessible :name
end
约会.rb
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
attr_accessible :appointment_date, :patient_id, :physician_id
end
病人.rb
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
attr_accessible :name
end
我想显示患者姓名、医生姓名和约会日期。这个怎么做。提前致谢。