sails.js + waterline一对多模型关联,删除Many时应该发生什么?

我和老师(一)和孩子(老师)之间有一对多的关系。

如果我做:

Teacher.destroy(teacherId).exec(function(err){}); 

孩子们不会自动移除。

这是一个错误,或者我应该手动删除它们? 如果这不是一个错误,不删除孩子的解释是什么?

水线目前不支持级联删除。 它可能是未来版本的configuration选项,但它可能永远不会是默认的。 在大多数生产就绪的应用程序中,您可能应该进行软删除。 在任何一种情况下,您都可以使用afterDestroy生命周期callback获得您想要的afterDestroy

api/models/Teacher.js ,类似于:

 module.exports = { attributes: { // attributes here }, afterDestroy: function(destroyedRecords, cb) { // Destroy any child whose teacher has an ID of one of the // deleted teacher models Child.destroy({teacher: _.pluck(destroyedRecords, 'id')}).exec(cb); } } 

你可以使用afterUpdate方法做类似的软删除操作。