所以我有三门课:
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, through: :appointments
end我正试图通过现有的医生记录来创建一个新的病人记录。
doctor = Physician.first
sick_person = doctor.patients.new
sick_person.save正在发生的事情是,病人记录被保存,但是合并记录,约会,没有被创建。我一直在阅读一些论坛,他们建议我使用inverse_of (https://github.com/rails/rails/issues/6161#issuecomment-6330795 ),这在使用a: have时似乎不对。
有谁知道如何记录下打火机表吗?我知道我也可以先创建病人记录,然后用那个病人id创建预约记录,但我想知道是否有更好的解决方案。
发布于 2014-06-28 01:17:38
尝试:
doctor = Physician.first
sick_person = Patient.new
doctor.patients << sick_personhttps://stackoverflow.com/questions/24462639
复制相似问题