gpt4 book ai didi

node.js - Sequelize .save() 在实例上不起作用

转载 作者:行者123 更新时间:2023-12-03 22:34:46 25 4
gpt4 key购买 nike

我有一个定义如下的模型。然后我尝试运行它下面的代码来更新检索到的实例的 isTeamLead 属性,但我收到错误 teamMember.save() is not a function

  const TeamMember = sequelize.define('teamMember', {
userId: Sequelize.INTEGER,
teamId: Sequelize.INTEGER,
slotNumber: Sequelize.INTEGER,
isTeamLead: Sequelize.BOOLEAN
});


Promise.all([db.models.TeamMember.findOne({ where: { $and: [{ userId: lead.id }, { teamId: id }] } })]).then((teamMember) => { teamMember.isTeamLead = true; teamMember.save() });

最佳答案

我能够通过确保我在实例上运行来解决这个问题。上面我操作的是数组而不是实际的 teamMember 实例。

    Promise.all([db.models.TeamMember.findOne({ where: { $and: [{ userId: lead.id }, { teamId: id }] } })]).then((teamMember) => { teamMember[0].isTeamLead = true; teamMember[0].save() });

关于node.js - Sequelize .save() 在实例上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62393201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com