2016-03-31 4 views
0

das Standardbeispiel für Ärzte und patiens verwendet durch StrongLoop (https://docs.strongloop.com/display/public/LB/HasManyThrough+relations) Unter der Annahme:Loopback Wie Abfrage in "hasManyThrough" Relation in der Basis zu den verwandten Modellen?

common/Modelle/physician.json

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

common/Modelle/patient.json

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

gemeinsame /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" 
    }, 

Lets supouse als One Physician kann 0,1,2 oder mehr Patienten haben. Auf diese Weise:

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

Wie kann ich alle Ärzte bekommen als den gleichen Patient hat ??

Am Beispiel:

Holen Sie sich alle Ärzte als haben die Patienten mit Patienten_ID 3 ??

In diesem Fall muss das Ergebnis sein: PhysicianId 2 und 3.

Antwort

Verwandte Themen