Loopback如何在“hasManyThrough”关系中查询相关模型?

时间:2016-03-31 04:05:22

标签: filter where has-many-through loopbackjs relation

假设StrongLoop(https://docs.strongloop.com/display/public/LB/HasManyThrough+relations)使用的医生和护士的标准示例:

公共/模型/ 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"
    },

公共/模型/ 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"
    },

让一位医生可以拥有0,1,2或更多患者。 这样:

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

我怎样才能让所有医生都拥有相同的患者?

以示例:

获得所有医生而不是患者患者3?

在这种情况下,结果必须是:PhysicianId 2和3.

1 个答案:

答案 0 :(得分:0)

GET /patients/{id}/physicians

methods added to the model

相关问题