Sequelize create object with associations(Sequelize 创建具有关联的对象)
问题描述
我正在尝试保存续集模型及其关联.所有的关联都是一对一的.从数据库中检索具有关联的模型可以正常工作,但插入它们是另一回事,文档只是让我更加困惑.
I'm trying to save sequelize models with their associations. All the associations are one to one. Retrieving models with associations from the database works just fine but inserting them is another matter and the documentation is just making me more confused.
这是我的插入方法:
models
.radcheck
.create(user, {
include: [{model: models.skraningar}, {model: models.radusergroup}, {model: models.radippool}]
})
.then(success, error);
我在文档和 stackoverflow 上都看到了很多方法来做到这一点,但到目前为止,这些方法对我来说都没有意义.有人愿意帮我清理一下吗?
I've seen so many ways to do this both in the documentation and here on stackoverflow and none of them make sense to me so far. Anyone care to clear things up for me?
推荐答案
我总是用外键关联模型来保存
I always save a model with association by it's foreign key
例如
models.user.create({ name : 'test', usergroup_id : 1 });
这篇关于Sequelize 创建具有关联的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Sequelize 创建具有关联的对象


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带更新的 sqlite CTE 2022-01-01