问题描述
经过一番研究,我没有发现与我的问题相关的任何内容.所以设置是已经与 sequelize (sqllite) 一起工作的 M:M 关系:
After some research I didn't find anything related to my problem. So the setting is an M:M relationship already working with sequelize (sqllite):
return User.find({ where: { _id: userId } }).then(user => {
logger.info(`UserController - found user`);
Notification.find({ where: { _id: notificationId } }).then(notification => {
if (associate) {
return user.addNotification([notification]);
} else {
return user.removeNotification([notification]);
}
})
})
问题是我在 inter 表(cityId,active)中有额外的字段,我不知道如何在运行addNotification"时更新它.
The thing is that I have extra fields in the inter table(cityId, active) and I don't know how to update it when running "addNotification".
提前致谢
推荐答案
如果您使用的是 Sequelize 4.x 版,API 中有一些变化
If you are using Sequelize version 4.x there is some changes in the API
关系添加/设置/创建设置器现在通过将属性作为 options.through 传递来设置它们(以前第二个参数被用作通过属性,现在它被认为是通过作为子选项的选项)
Relationships add/set/create setters now set through attributes by passing them as options.through (previously second argument was used as through attributes, now its considered options with through being a sub option)
user.addNotification(notification, { through: {cityId: 1, active: true}});
这篇关于使用额外的列将多对多序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!