【发布时间】:2014-12-07 13:15:02
【问题描述】:
我的模型设置:
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 :physicians, :through => :appointments
end
在我的应用程序中登录用户是医生、患者或管理员,我了解到医生和患者的关系如何与预约一起工作,但是如何为此设置用户模型和表格
class User_type < ActiveRecord::Base
belongs_to :doctors, class_name: "USER"
belongs_to :patients, class_name: "USER"
end
我知道我在这里缺少关键的自我关联,但我该如何做到这一点,或者以任何其他方式为此设置这些模型和表格。提前致谢。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 associations has-many-through