我有这样的方法:
const getAllRequest = async (page, pageSize, order) => {
try {
const requests = await Request.findAndCountAll({
where = {
[Op.or]: [
sequelize.where(sequelize.col('requests.id'), { [Op.like]: `%${req.query.queryStr}%` }),
sequelize.where(sequelize.col('requests.user_id'), { [Op.like]: `%${req.query.queryStr}%` }),
sequelize.where(sequelize.col('requests.uuid'), { [Op.like]: `%${req.query.queryStr}%` }),
sequelize.where(sequelize.col('requests.status'), { [Op.like]: `%${req.query.queryStr}%` }),
sequelize.where(sequelize.col('requests.csv_url'), { [Op.like]: `%${req.query.queryStr}%` }),
sequelize.where(sequelize.col('request_urls.url'), { [Op.like]: `%${req.query.queryStr}%` }),
]
},
raw: true,
attributes: ['id', 'uuid', 'userId', 'status', 'csvUrl', 'requestURLs.url', 'createdAt', 'updatedAt'],
include: [{
model: RequestUrl,
as: "requestURLs",
where: { type: 'brand' },
attributes: []
}],
subQuery: false,
offset: page * pageSize,
limit: pageSize,
order
});
return {
status: 200,
message: "List of requests.",
requests
}
} catch (error) {
return Promise.reject({
status: 500,
message: "Something went wrong.",
error
});
}
}
但如果尝试使用包含的模型属性进行过滤,它不会返回数据。相反,它返回:
错误:“where 子句”中的未知列“request_urls.url”
请帮我解决这个问题。
qq_笑_17
翻阅古今
相关分类