[英]MySQL many-to-many relationship in LoopBack
I'm having trouble getting LoopBack to perform a many-to-many join query. 我无法让LoopBack执行多对多联接查询。 Considering the hasManyThrough example from the documentation :
考虑文档中的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});
If I try to do a single search to find Patients associated with a particular doctor who have a zip code of 10012, I could try: 如果我尝试进行一次搜索以查找与邮政编码为10012的特定医生相关的患者,则可以尝试:
physician.patients({where: {zip: 10012}}, fn);
However, the search on the physician's patients is actually only searching on the Appointments table. 但是,对医师患者的搜索实际上仅是在“约会”表上的搜索。 Is there any way to do a simple search that will be performed on the specific physician's patients directly?
有什么方法可以直接对特定医师的患者进行简单搜索吗?
LoopBack implements the hasMany/through relation for physician.patients() as follows: LoopBack如下实现了doctor.patients()的hasMany / through关系:
Appointment.find ({ where: { physicianId: 1 },
include: 'patient',
collect: 'patient' }, callback);
We're considering to support the filter for the 'include' which brings int 'patient' information. 我们正在考虑为包含“ int”“患者”信息的“ include”过滤器提供支持。
I suggest you open an issue at https://github.com/strongloop/loopback-datasource-juggler/issues . 我建议您在https://github.com/strongloop/loopback-datasource-juggler/issues打开一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.