include下条件查询并且允许为空
添加required: false即可。
const where = {
[Op.and]: [
s && {
[Op.or]: {
name: {
[Op.substring]: s
},
mobile: {
[Op.substring]: s
}
}
},
]
};
include: {
...(!s && {required: false}),
model: Account,
where,
attributes: ['name', 'mobile'],
},