sails js 0.10.0-rc7无法删除多对多关联

时间:2014-05-23 11:17:16

标签: sails.js waterline sails-mongo

我使用Sails @ beta 0.10.0-rc5,我升级到rc7,我的单元测试在多对多关联中失败了!

我与中心之间的多对多关系' &安培; '教师'楷模。

**我在下面添加了调试结论**

CenterController.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] ]

**调查结论**

水线\ lib中\水线\模型\ 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' }

问题(我猜)

在" IN SAVE FUNCTION"之后,打印出remove.js的最后一个输出。来自center.save()的文字

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

看起来这是Waterline中的一个错误,detailed in this report。感谢您的报告和您的支持 - 该错误已经修补,并且很快就会推出新的RC。在此期间,您可以通过将Waterline RC4的 lib / waterline / model / lib / defaultMethods / save.js 中的第104行更改为:

来自行申请the patch
addAssociations: ['buildAssociationOperations', 'updateRecord', function(next, results) {

或从https://github.com/balderdashy/waterline.git查看Waterline的主分支,并替换Sails安装的 node_modules 文件夹中存在的副本。