我正在尝试在 LoopBack 2.1.2 中建立多对多关系
http://docs.strongloop.com/display/LB/HasManyThrough+relations
我试图 POST /api/patients/:patientId/physicians 来创建一个新的医生,它将 patientId 链接到新的医生,但没有在约会模型中设置约会日期。
是否有一个 API 调用可以在一个事务中创建它?为患者添加新医生并设置约会日期的最佳方法是什么?我必须创建自己的 RESTFUL API 调用吗?
这些是我的 json 模型
文件名:约会.json
{
"name": "appointment",
"base": "PersistedModel",
"relations": {
"patient": {
"type": "belongsTo",
"model": "patient"
},
"physician": {
"type": "belongsTo",
"model": "physician"
}
},
"properties": {
"appointmentDate": {
"type": "string"
}
},
"validations": [],
"acls": [],
"methods": []
}
文件名:患者.json
{
"name": "patient",
"base": "PersistedModel",
"relations": {
"physicians": {
"type": "hasMany",
"model": "physician",
"through": "appointment"
}
},
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"acls": [],
"methods": []
}
文件名:医师.json
{
"name": "physician",
"base": "PersistedModel",
"relations": {
"patients": {
"type": "hasMany",
"model": "patient",
"through": "appointment"
}
},
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"acls": [],
"methods": []
}