/ / Loopback Comment interroger la relation “hasManyThrough” en base avec les modèles associés? - filtre, où, relation multiple, boucle de retour

Loopback Comment interroger la relation “hasManyThrough” en base avec les modèles associés? - filtre, où, relation multiple, boucle de retour

En supposant l’exemple type de médecins et de patiens utilisé par StrongLoop (https://docs.strongloop.com/display/public/LB/HasManyThrough+relations):

common / models / administrator.json

{
"name": "Physician",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"patients": {
"type": "hasMany",
"model": "Patient",
"foreignKey": "patientId",
"through": "Appointment"
},

common / models / patient.json

{
"name": "Patient",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"physicans": {
"type": "hasMany",
"model": "Physician",
"foreignKey": "physicianId",
"through": "Appointment"
},

common / models / nomination.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"
},

Permet à un seul médecin d'avoir 0,1,2 patient ou plus. Par ici:

PhysicianId | PatientId
1----------------1
1----------------2
2----------------3
2----------------4
3----------------3
3----------------5

Comment puis-je obtenir tous les médecins que d'avoir le même patient?

Par exemple:

Obtenez tous les médecins que les patients avec patientId 3 ??

Dans ce cas, le résultat doit être: PhysicianId 2 and 3.

Réponses:

0 pour la réponse № 1
GET /patients/{id}/physicians

Voir méthodes ajoutées au modèle.