Я пытался заключить эти 2 запроса в транзакцию, подобную этой
const transaction = await db.sequelize.transaction()
try {
await Table1.create({
name: data.name
}, {transaction});
trainees.foreach(async trainee => {
await Table2.create({
name: trainee.name
}, {transaction});
})
await transaction.commit();
api.publish(source, target, false, {message: `Data successfully saved`});
} catch (error) {
await transaction.rollback();
api.error(source, target, {
message: error.message || `Unable to save data`
});
}
Первый запрос выполнен, но во втором запросе появляется следующая ошибка.
commit has been called on this transaction(2f8905df-94b9-455b-a565-803e327e98e1), you can no longer use it. (The rejected query is attached as the 'sql' property of this error)