尝试在 where 子句中强制转换列以搜索查询。很难找到有关如何执行此操作的可靠文档。有什么想法吗?
return await User.findAndCountAll({
where: {
[Op.or]: {
'email': { [Op.iLike]: `%${query}%` },
'$id::text$': { [Op.iLike]: `%${query}%` } // id is int but needs to be string for searching
}
},
limit,
offset: page * limit,
order: [[sortBy, sortOrder.toUpperCase()]],
raw: true,
logging: console.log
});
最佳答案
我认为这就是您要搜索的内容:
where: {
[Op.or]: [
{email: {[Op.iLike]: `%${query}%`}},
sequelize.where(
sequelize.cast(sequelize.col('User.id'), 'varchar'),
{[Op.iLike]: `%${query}%`}
),
],
},
关于javascript - 在 where 子句中将强制转换列序列化为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47212187/