1

我使用 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”文本之后

任何想法?

4

1 回答 1

0

Looks like this was a bug in Waterline, as detailed in this report. Thanks for the report and for your support--the bug has been patched and a new RC should be pushed soon. In the meantime you can either apply the patch yourself by changing line 104 in lib/waterline/model/lib/defaultMethods/save.js of Waterline RC4 to:

addAssociations: ['buildAssociationOperations', 'updateRecord', function(next, results) {

or check out the master branch of Waterline from https://github.com/balderdashy/waterline.git and replace the copy that exists in your Sails install's node_modules folder.

于 2014-05-26T22:08:40.900 回答