【问题标题】:Saving and reading three models in Cakephp在 Cakephp 中保存和读取三个模型
【发布时间】:2012-06-28 09:31:52
【问题描述】:

我正在努力加入三个模型。我有医院、医生和专科。 Hospital hasAndBelongsToMany DoctorDoctor hasAndBelongsToMany Specialty。因此,一位医生可以在 1 家具有 1 个专业的医院工作,但同一位医生可以在另一家具有其他专业的医院工作。

我需要在数据库中创建一个表来连接 3 个这样的模型:

表:医生_医院_专科 字段:ID |医生 ID |医院 ID | special_id

但这对我不起作用。我在很多论坛中搜索了实现此功能的方法,但我找不到任何东西。请帮忙!

【问题讨论】:

    标签: cakephp model save has-and-belongs-to-many


    【解决方案1】:

    制作DoctorsHospitalsSpecialties 模型。

    Doctor hasMany DoctorsHospitalsSpecialties
    Hospital hasMany DoctorsHospitalsSpecialties
    Specialty hasMany DoctorsHospitalsSpecialties
    
    DoctorsHospitalsSpecialties belongsTo Doctor, Hospital, Speciality.
    

    您可能必须自己编写一些代码来管理 DoctorsHospitalsSpecialties 模型中的数据。

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多