我是全新的rails,所以這可能是一個微不足道的問題。在閱讀教程時,我已閱讀關於關係標識符has_many和has_many的教程。我似乎無法理解的是它們之間的差異。舉例來說,如果我有3個型號,醫生,約會和患者rails has_many vs has_many through?
class Doctor< ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :doctor
belongs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :doctors, through: :appointments
end
我不能只是說,醫生的has_many:患者和患者的has_many:醫生,他們會扯上關係?通過約會來達到這個目的的目的是什麼?
感謝