0

我无法让 LoopBack 执行多对多连接查询。考虑文档中的 hasManyThrough 示例:

var Physician = ds.createModel('Physician', {name: String});
var Patient = ds.createModel('Patient', {name: String});

var Appointment = ds.createModel('Appointment', {
    physicianId: Number,
    patientId: Number,
    appointmentDate: Date
});

Appointment.belongsTo(Patient);
Appointment.belongsTo(Physician);

Physician.hasMany(Patient, {through: Appointment});
Patient.hasMany(Physician, {through: Appointment});

如果我尝试进行一次搜索以查找与邮政编码为 10012 的特定医生相关的患者,我可以尝试:

physician.patients({where: {zip: 10012}}, fn);

但是,对医生患者的搜索实际上只是在 Appointments 表中进行搜索。有什么方法可以直接对特定医生的患者进行简单的搜索?

4

1 回答 1

1

LoopBack 为医生.患者()实现了 hasMany/through 关系,如下所示:

Appointment.find ({ where: { physicianId: 1 },
  include: 'patient',
  collect: 'patient' }, callback);

我们正在考虑支持“包含”过滤器,它会带来“患者”信息。

我建议您在https://github.com/strongloop/loopback-datasource-juggler/issues打开一个问题。

于 2014-03-05T06:47:04.790 回答