ppshein ppshein - 8 months ago 77
Node.js Question

Error: where: "raw query" has been removed, please use where ["raw query", [replacements]]


Unhandled rejection Error: where: "raw query" has been removed, please
use where ["raw query", [replacements]]


I encountered this error while rendering the following code. It's a dynamic
where
clause, generated by the value entered by user in the
search
field:

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');
}


How can I resolve this?

Answer Source

Raw query should be array

queryWhere = {
    $and: [
        {$or: [
            [searchGender],
            [searchExperience]]}
    ]
};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download