在我的应用程序中,我已经在User和Project表之间建立了关联。使用此代码:
User.belongsToMany(Project, {
through: "users_projects"
});
Project.belongsToMany(User, {
through: "users_projects"
});
当我做一个简单的发布请求时,我收到以下错误:
currentUser.addProject 不是函数
app.post("/project", async (req, res, next) => {
try {
const project = await Project.findOrCreate({
where: {
name: req.body.name,
content: req.body.content
}
});
const currentUser = await User.findAll({
where: { id: req.body.userId }
});
console.log(currentUser);
await currentUser.addProject(project[0]);
res.json(project[0]);
} catch (error) {
next(error);
}
});
什么可能导致这个问题?
慕森卡
相关分类