如何在一个操作中保存SailsJS中的多个logging?

我想知道最好的做法是保存多个logging的操作,使更改,特别是添加和删除多个logging。 最终目标是让一个function可以访问操作中所有已更改的数据。 目前我正在嵌套保存,以便最内层的保存可以访问所有更新logging中的数据。 这里是我如何保存的一个例子:

record1.save(function (error, firstRecord) { record2.save(function (erro, secondRecord) { record3.save(function (err, thirdRecord) { res.send({recordOne: firstRecord, recordTwo: secondRecord, recordThree: thirdRecord}); }); }); }); 

通过这种保存结构,recordOne,recordTwo和recordThree在服务器上显示期望值。 但是,检查localhost / 1337 / modelName显示模型没有正确更新,并有不正确的数据。

你可以使用内置的诺言引擎蓝鸟来。

  Promise.then(function() { return [record1.save(),record2.save(),record3.save()]; }).spread(function(record1_saved,record2_saved,record3_saved){ res.send({recordOne: record1_saved, recordTwo: record2_saved, recordThree: record3_saved}); req.namespamce = this; }).catch(function(err){ res.badRequest({ error: err.message }); req.namespamce = this; });