ruby & 레일을 배우려면 http://guides.rubyonrails.org/을 사용하고 있습니다. 3 개의 테이블을 조인하는 데 문제가 있습니다. 그래서이 예제로 새로운 프로젝트를 만들어 : http://guides.rubyonrails.org/association_basics.html#the-has_many_through-association 내가 세 개의 테이블 의사를 가지고, 약속 & 환자Rails3의 세 테이블 합치기
모델 :
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
의사 이름 & appointment_date라는 환자 이름을 표시하고 싶습니다. 어떻게하는지. 사전에 감사합니다.
에서 당신이이 모델에 내장 된 컨트롤러와 뷰가 있습니까? –
예 컨트롤러와 3 가지 모델 모두에 대한 뷰가 있습니다. –
그럼,보기에서 모델과 연관을 액세스하는 방법에 대해 궁금한 점이 있습니까? –