gpt4 book ai didi

javascript - Sequelize 更新或创建包含的关联

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

拥有 Sequelize hasOne 关联:

const User = sequelize.define('user', {/* ... */})
const Project = sequelize.define('project', {/* ... */})

// One-way association
User.hasOne(Project)

并且用户实例 已经存在 。我们如何添加新的 Project 并将其连接到 User 实例?

首先,我们需要找到 User :
const user = await models.users.findOne({
where: { id: 1 },
include: models.projects
});

我们下一步怎么办?如果 user.projectnull 呢?

最佳答案

关于javascript - Sequelize 更新或创建包含的关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54986027/

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