我有像下面的图片模型:
并且这些关系被定义为:
Level.hasMany(DoctorSpecializtion);
DoctorSpecializtion.belongsTo(Level);
DoctorSpecializtion.belongsTo(Specialization)
Doctor.hasMany(DoctorSpecializtion)
DoctorSpecializtion.belongsTo(Doctor)
Service.belongsToMany(Doctor, { through: DoctorService })
Doctor.belongsToMany(Service, { through: DoctorService })
Service.hasMany(DoctorService)
DoctorService.belongsTo(Service)
Doctor.hasMany(DoctorService)
DoctorService.belongsTo(Doctor)
现在,当我包括DoctorService或DoctorSpecializtion时,查找和计数所有返回错误的数字。我也试过separete:true
include: [
{
separate: true,
model: DoctorSpecializtion,
attributes: ['id'],
where: { specializationId: { [Op.or]: value } },
include: [
{
model: Specialization,
attributes: ['title', 'slug'],
},
{
model: Level,
attributes: ['title', 'slug'],
},
],
},
],
但是当我使用separate true的过滤部分是
where: { specializationId: { [Op.or]: value } },
它确实返回了我需要结果。
1条答案
按热度按时间tmb3ates1#
我通过从我的查询中删除separate:true并将此查询添加到我的findAndCountAll查询中来修复此问题