我正在尝试使用hasMany通过关联使用此处的示例:http://docs.sequelizejs.com/en/2.0/docs/associations/#belongs-to-many-associations
基本上,我的模型是:
User:
User.hasMany(models.Projects, {through: models.Project_User});
Project:
Project.hasMany(models.User, {through: models.Project_User});
Project_User has custom fields:
status
is_default
问题是当我尝试使用
添加到此时 user.setProjects(project).then(function(res){
在插入之前删除之前存在的值之前,它会删除Project_User中的记录。
Executing (default): SELECT status,is_default FROM `Project_Users` AS `Project_User` WHERE `Project_User`.`UserId` = 26;
Executing (default): DELETE FROM `Project_Users` WHERE `UserId` = 26 AND `ProjectId` IN (1726)
Executing (default): INSERT INTO `Project_Users` (`id`,`is_admin`,`ProjectId`,`UserId`) VALUES (NULL,0,873,26);
如何防止DELETION发生???
答案 0 :(得分:0)
您应该使用templates/joomlatemplate
代替:
addProjects()