gpt4 book ai didi

node.js - 未处理的PromiseRejectionWarning : SequelizeDatabaseError: Unknown column 'model.coulmn_name' in 'where clause'

转载 作者:行者123 更新时间:2023-12-03 22:24:48 26 4
gpt4 key购买 nike

我使用 Sequelize
我想从另一个模型中搜索 userId
当我添加 "task_customer_order.userId" 我得到错误但是当我删除它时只有 userId 它的工作但是 的外键 userId 评论
我的代码:

 count_comment:async(req,res)=>{
var Sequelize = require('sequelize');
const id = req.params.id;

await Comment.findAll({
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('comment.publish')), "count_Comment"]],
},
include: ['task_customer_order'],
where:[{"publish":1,"task_customer_order.userId":{[Op.like]:id}}],
}).then(data => {
res.send(data)
})

},
错误:
UnhandledPromiseRejectionWarning: SequelizeDatabaseError: Unknown column 'comment.task_customer_order.userId' in 'where clause'
没有用户 ID 的输出:
{
"id": 1,
"title_body": "1",
"publish": true,
"createdAt": "2021-01-04T17:34:46.000Z",
"updatedAt": "2021-01-04T17:57:52.000Z",
"taskCustomerOrderId": 1,
"userId": 2, <============= i don't need it
"count_Comment": 6,
"task_customer_order": {
"id": 1,
"title_task": "yy",
"description": "",
"endAt": "2021-02-12T21:00:00.000Z",
"duration": "09-02",
"publish": true,
"createdAt": "2021-01-04T17:32:47.000Z",
"updatedAt": "2021-01-04T21:49:15.000Z",
"customerOrderId": 1,
"userId": 1 <==================== i want this
}
}

最佳答案

如果您想在加入的 task_customer_order 中按 userId 过滤 - 您需要将条件放在 include 中。尝试下一个:

await   Comment.findAll({
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('comment.publish')), "count_Comment"]],
},
include: [{ model: TaskCustomerOrder, where:{userId: {[Op.like]:id}}}],
where:{"publish”:1},
}).then(data => {
res.send(data)
})

关于node.js - 未处理的PromiseRejectionWarning : SequelizeDatabaseError: Unknown column 'model.coulmn_name' in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65570523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com