【发布时间】:2015-07-31 10:08:20
【问题描述】:
我想在不删除医师的情况下删除患者及其所有约会。
采取以下关联:
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, through: :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
每次我移除患者时,我都会失去该患者甚至接触过的所有医生(通过预约)。医生可能只见过一名患者..但这不是在患者被移除时移除医生的理由。
我觉得我需要类似的东西
class Physician < ActiveRecord::Base
has_many :appointments, dependant: hell no!
有人可以帮助我吗?是否有可能 has_many through 关系是错误的解决方案?
谢谢
编辑:我绝不希望由于相关的患者或医师离开手术而从系统中移除患者或医师。
如果医生离开,这并不意味着患者也会离开。虽然我很高兴他们的约会被取消。同样,如果患者离开,这并不意味着我的医生也会离开。
【问题讨论】:
-
"注意依赖: :restrict_with_exception。这将导致 Active Record 拒绝销毁任何具有关联约会记录的医师记录。"我想要一个直升不要破坏。我可以在没有 has_many through 关系的情况下做到这一点。但是构建表单和控制器是一件很痛苦的事情。
标签: ruby-on-rails ruby-on-rails-4 associations has-many-through