【发布时间】:2020-02-22 18:15:06
【问题描述】:
我已经了解了关系标识符 has_many 和 has_many through。我似乎无法理解的是它们之间的区别。例如,如果我有 3 个模型,医生、约会和患者
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
我不能只说 Doctor has_many :patients 和 Patient has_many :doctors 并且他们是相关的吗?通过预约来做这件事的目的是什么?
谢谢
【问题讨论】:
标签: ruby-on-rails