在我的應(yīng)用程序中,我已經(jīng)在User和Project表之間建立了關(guān)聯(lián)。使用此代碼:User.belongsToMany(Project, { through: "users_projects"});Project.belongsToMany(User, { through: "users_projects"});當(dāng)我做一個(gè)簡(jiǎn)單的發(fā)布請(qǐng)求時(shí),我收到以下錯(cuò)誤:currentUser.addProject 不是函數(shù)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); }});什么可能導(dǎo)致這個(gè)問題?
addProject 不是函數(shù)(續(xù)集)
湖上湖
2022-10-08 15:08:25