未处理的拒绝错误:其中:“原始查询”已被删除,请
使用位置:[“原始查询”,[replacements]]
在呈现以下代码时遇到此错误。这是一个动态where
子句,由用户在search
字段中输入的值生成:
var queryWhere = {id: {$ne: null}};
if (req.query) {
if (req.query.gender && req.query.gender !== '') {
searchGender = "gender = '" + req.query.gender + "'";
} else if (req.query.gender && req.query.gender === '') {
searchGender = "gender IS NOT NULL ";
}
if (req.query.experience && req.query.experience !== '') {
searchExperience = "experience = '" + req.query.experience + "'";
} else if (req.query.gender && req.query.experience === '') {
searchExperience = "experience IS NOT NULL ";
}
queryWhere = {
$and: [
{$or: [
searchGender,
searchExperience]}
]
};
models.Users.findAll({
offset: numPerPage * 50,
limit: 50,
where: queryWhere,
include: [
{model: models.Users_Answers}
],
order: [
[models.Sequelize.col('id'), 'ASC'],
[models.Users_Answers, 'id', 'ASC']
]
}).then(function(answers) {
res.render('answers', {answers: answers, search: req.query.searchParam, moment: moment, pagesize: (numPerPage+1), total: totalCount / 50});
});
} else {
res.render('answers');
}
我该怎么解决?
最佳答案
原始查询应为数组
queryWhere = {
$and: [
{$or: [
[searchGender],
[searchExperience]]}
]
};