Ruby Rails。我正在尝试将医生的预约与用户(医生和患者)联系起来。有一个用户模型,它有患者和医生的角色。链接这个的最佳方式是什么?预约应该只有一名医生和一名用户分配到一个预约位置。谢谢你的帮助
attr_accessible :email, :password, :password_confirmation, :remember_me, :dob, :first_name, :last_name, :gender, :doctor, :pps_no, :specialisation_id, :roles, :roles_id, :roles_name, :appointments, :appointments_id
# attr_accessible :title, :body
has_many :appointments, :through => :users_appointments
has_many :users_appointments
has_and_belongs_to_many :specialisations
has_many :roles, :through => :roles_users
has_many :roles_users
has_secure_password
GENDERS = [ "Female", "Male" ]
#Roles = %w[admin, doctor, patient]
def role?(role)
return !!self.roles.find_by_name(role.to_s)
end
答案 0 :(得分:0)
关于协会的Ruby on Rails指南实际上非常好地说明了你在寻找什么:医生,约会和患者:
http://guides.rubyonrails.org/association_basics.html#the-has_one-through-association