【发布时间】:2018-01-05 15:20:49
【问题描述】:
我在事务链代码中有多个循环,但在循环完成后事务立即提交链而不继续下一个查询。我的代码是这样的:
return sm.sequelize.transaction(function (t) {
return Room.create({
room_type: req.body.room_type
},{transaction: t}).then(function(roomtype){
for (i=0;i<room.length;i++){
return Roomtype.create({
name : req.body.roomtype[i]
},{transaction: t}); //my transaction only work untill here and commit after that
}
for (i=0;i<another.length;i++){ //I need to continue my query to second loop here
return User.create({
email :req.body.email[i]
},{transaction:t});
}
}).then(function(result){
}).catch (function(err){
})
})
那么如何让循环后的交易进入下一个循环呢?
【问题讨论】:
标签: javascript express transactions sequelize.js