我使用 Sails@beta 0.10.0-rc5,我升级到 rc7,我的单元测试在多对多关联上失败了!
我在“中心”和“教师”模型之间存在多对多关系。
**我在下面添加了调试结论**
中心控制器.js:
sails.log.info("before remove teachers: ", center.teachers);
sails.log.info("removing teacher = '", req.param('teacher_id'));
center.teachers.remove(req.param('teacher_id'));
sails.log.info("after remove teachers: ", center.teachers);
center.save(function(err) {if(err)... sails.log.info("IN SAVE FUNCTION"); ...});
输出:
before remove teachers: [ { id: '537f19dbeb09ff341598c77b' },
add: [Function: add],
remove: [Function: remove] ]
removing teacher = 537f19dbeb09ff341598c77b
after remove teachers: [ { id: '537f19dbeb09ff341598c77b' },
add: [Function: add],
remove: [Function: remove] ]
** 调试结论**
waterline\lib\waterline\model\lib\associationMethods\remove.js
// line 240
// Build up criteria and updated values used to create the record
var criteria = {};
criteria[associationKey] = pk;
criteria[attribute.on] = this.proto[this.primaryKey];
console.log('criteria: ', criteria);
输出:
criteria: { teacher_centers: '537f24b98e64e7fc1de20718',
center_teachers: '537f19dbeb09ff341598c77b' }
问题(我的猜测):
remove.js 的最后一个输出打印在 center.save() 的“IN SAVE FUNCTION”文本之后。
任何想法?