0
假设通过使用StrongLoop医生和patiens的标准的例子(https://docs.strongloop.com/display/public/LB/HasManyThrough+relations):Loopback如何查询基于“hasManyThrough”关系的相关模型?
公共/模型/ physician.json
{
"name": "Physician",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"patients": {
"type": "hasMany",
"model": "Patient",
"foreignKey": "patientId",
"through": "Appointment"
},
公共/模型/ patient.json
{
"name": "Patient",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"physicans": {
"type": "hasMany",
"model": "Physician",
"foreignKey": "physicianId",
"through": "Appointment"
},
共同/models/appointment.json
{
"name": "Appointment",
"base": "PersistedModel",
"properties": {
"appointmentDate": {
"type": "date"
}
},
"validations": [],
"relations": {
"physician": {
"type": "belongsTo",
"model": "Physician",
"foreignKey": "physicianId"
},
"patient": {
"type": "belongsTo",
"model": "Patient",
"foreignKey": "patientId"
},
让supouse比一位医生可以有0,1,2或更多患者。 这样:
PhysicianId | PatientId
1----------------1
1----------------2
2----------------3
2----------------4
3----------------3
3----------------5
我怎样才能让所有的医生比拥有相同的病人?
例如:
获取所有的医生比有patientId 3的患者?
在这种情况下其结果必然是:PhysicianId 2和3