include另一张表时的默认情况,即required:false;
当include中包含where语句限定时,会将其自动变为inner join,此时即为required:true;
此时即使设定为false也无效。
若需left out join且联表查询时,可使用顶层where语句,即$,如下所示:
let where={};
if (options.evaluationLevel === '优') {
where['$evaluation.structure_evaluation_level$'] = options.evaluationLevel;
} else {
where['$evaluation.structure_evaluation_level$'] = options.evaluationLevel;
}
const result = await this.app.model.AAA.findAndCountAll({
...options.page,
raw: true, nest: true,
where,
order: [[ 'routeCode', 'ASC' ], [ 'unitNo', 'ASC' ]],
include: [{
required: false,
model: this.app.model.BBB,
as: 'cost',
attributes: [ 'maintainTotalMny' ],
}, {
required: false,
model: this.app.model.CCC,
as: 'evaluation',
attributes: [ 'structureEvaluationLevel' ],
}],
});