【发布时间】:2016-11-20 03:18:26
【问题描述】:
如何使用对象创建具有现有关联的条目?
例如,
User.create({
socialMedia: [{
socialId: 1, //should reference existing social media
userSocialMedia: {
name: 'foo' //should create new "through" entry
}
}],
bank: {
bankId: 1 //should reference existing bank
});
我可以User.create({ bankId: 1 }),但是由于客户端发送的数据是这种形式,有没有办法告诉sequelize是为每个包含的模型添加新的还是使用现有的?
【问题讨论】:
标签: sequelize.js