【发布时间】:2020-03-16 06:33:08
【问题描述】:
大家好,
我对使用 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);
});
});
});
欢迎所有线索! :)
【问题讨论】:
标签: sequelize.js