【发布时间】:2017-03-17 23:23:45
【问题描述】:
我有两个型号users 和appointments。
users 模型如下-
{
"users": {
"0": {
"id": "1",
"name": "test1",
"role": "doctor"
},
"1": {
"id": "2",
"name": "test2",
"role": "patient"
},
"2": {
"id": "3",
"name": "test3",
"role": "support"
}
}
}
现在在上面的模型中,如果角色是医生,我们称它为doctor_id,如果是patient,那么patient_id等等。
现在我的约会模式如下->
{
"name": "appointments",
"plural": "appointments",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"appointmentDate": {
"type": "date"
},
"appointmentTime": {
"type": "string"
},
"doctorId": {
"type": "string"
},
"patientId": {
"type": "string"
}
},
"validations": [],
"relations": {
"Doctor": {
"type": "belongsTo",
"model": "users",
"foreignKey": "doctorId"
},
"Patient": {
"type": "belongsTo",
"model": "users",
"foreignKey": "patientId"
}
},
"acls": [],
"methods": {}
}
所以当我尝试GET 所有约会时,它不会从users 发送关系数据。如果我添加单个关系,它会按预期工作,但不能处理来自同一模型的多个关系。
提前致谢,
【问题讨论】:
-
按照我的做法,我相信外键应该是“”。您不应该定义医生 ID 和患者 ID,您可能必须在用户类中使用外键“医生”和“患者”定义两个 hasMany 关系
-
@user3802077:谢谢你的回复,但无法得到你真正想表达的内容,你能举例说明一下吗?
标签: node.js mongodb loopbackjs loopback-address