sequelize.js - Sequelize v5:在 Create 的 then 中的 FindAll 不检索创建的行
问题描述
大家好,我在使用 MySQL 数据库的 Sequelize v5 时遇到问题。
当我在执行创建后尝试对模型执行 findAll 时,我没有刚刚创建的模型。我应该怎么做才能解决这个问题?
这是有问题的代码,它的作用是:
我创建了一个演员,我将它链接到一个关联表,然后我做了一个 findAll。我确定演员创建良好(存在于 BDD 中,与关联表相同,控制台中显示“提交”,并且我有在 findAll 之前创建的演员的返回 id)。
return Actor.create({
firstname: req.body.firstname,
lastname: req.body.lastname,
mobile: req.body.mobile,
email: req.body.email,
city: req.body.city,
zipcode: req.body.zipcode
}).then(function (rowCreated1) {
return Asso_role_school_actor.create({
id_actor: rowCreated1.id_actor,
id_role: 1,
id_school: req.body.id_school
}).then(function () {
return Actor.findAll({
attributes: ['id_actor', 'firstname', 'lastname', 'email', 'mobile', 'city', 'zipcode'],
include: [{
model: Asso_role_school_actor,
where: {
id_role: 1,
id_school: req.params.id_school,
finishAt: null
},
attributes: []
}]
}).then((results) => {
console.log(results);
return res.status(200).send(results);
});
});
});
欢迎所有线索!:)
解决方案
您正在使用 req.body.id_school 保存对象,但在 find 方法的包含中使用 req.params.id_school。也许这是造成麻烦?
推荐阅读
- javascript - 更改使用 JSON 动画的 SVG 的 CSS 中的颜色
- php - PHP Session 文件权限被拒绝
- c# - 如何解释这个“调用不明确”的错误?
- docker - 来自守护进程的错误响应:冲突:无法删除存储库引用“portainer/portainer:latest”(必须强制)
- ocaml - 使用 opam 安装程序后,如何运行它?
- apache-drill - 如何在 apache 演习中将限制偏移与 where 子句一起使用?
- sql-server - 在登录后阶段连接 SQL Server 超时
- javascript - 如何将列表附加到 FormData?
- c# - 垃圾收集器不以相同的方法处理 Excel 实例
- java - 我如何解决空指针异常我无法在我的片段上得到任何东西