【发布时间】:2019-07-07 15:47:24
【问题描述】:
我是 Sequelize ORM 的新手。我想将 SQL 查询转换为 Sequelize 查询。
这是我的 SQL 查询,我想将此查询转换为 sequelize 查询:
SELECT * FROM `Posts` AS `Posts`
WHERE `Posts`.user_id IN
(SELECT `Follows`.receiver_id FROM `follows` AS `Follows`
WHERE `Follows`.user_id = user_id and `Follows`.status = "accept");
我试过了,但它没有返回任何数据:
Posts
.findAll({ where: {
user_id: { [Op.in]: [{
include: [{
model: Follows,
attributes: ['receiver_id'],
where: {
user_id: user_id,
status:status
}
}]
}]
}
}})
.then(users => { res.send(users); })
执行上述代码后,控制台报错
SELECT `event_id`, `user_id`, `event_message`, `e_imagepath`,
`createdAt`, `updatedAt`, `receiver_id`
FROM `Posts` AS `Posts`
WHERE `Posts`.`user_id` IN ('[object Object]');
我想将 SQL 查询转换为 Sequelize 查询。
【问题讨论】:
标签: mysql express sequelize.js