我无法让 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 表中进行搜索。有什么方法可以直接对特定医生的患者进行简单的搜索?