我是全新的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:医生,他们会扯上关系?通过约会来达到这个目的的目的是什么?
感谢