【发布时间】:2015-10-16 07:03:28
【问题描述】:
我已通读 basics of association,但我的应用程序适合 `has_many :through 关联...但我的 other question 缺少一个问题。
我宁愿再问一个问题,只是为了让我的问题清晰明了。
根据我对 has_many :through 关联如何工作的理解,每当医生有新患者时,都会为该患者创建或必须创建一个新预约。虽然这完全有道理,但my app 一点也不喜欢。
就我而言,每当用户“喜欢”某人的帖子时,它都会创建一个新帖子。我一点也不想要。我正在尝试了解 Rails 协会,以便我可以回答与此相关的其他问题。如何防止自动创建另一个“约会”?或者更确切地说,当patient 的新实例被创建并合并到doctor.patients 时,它会创建一个新约会。
d = Doctor.new
p = Patient.new
a = Appointment.new # created or not
foo = Doctor.find(1)
foo.patients << p # this creates a new appointment which i do not want.
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 activerecord