I use Sails@beta 0.10.0-rc5, I upgraded to rc7 and it my unit tests failed on Many-To-Many association!
I've Many-To-Many relation between 'Center' & 'Teacher' models.
** I ADDED DEBUGGING CONCLUSIONS BELOW **
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"); ...});
OUTPUT:
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] ]
** DEBUG CONCLUSIONS**
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);
OUTPUT:
criteria: { teacher_centers: '537f24b98e64e7fc1de20718',
center_teachers: '537f19dbeb09ff341598c77b' }
Problem (my guess):
The last output from remove.js is printed after the "IN SAVE FUNCTION" text from center.save().
Any idea?