Filipe_Cunha
I’m have tested your code, but the rollback does not work.
return await strapi.db.connection.transaction(async (transacting) => {
// Find the user
try{
const fromUser = await strapi.query('api::local.local').create({ data:{id:444 }}, null, { transacting });
const toUser = await strapi.query('api::local.local').create({ data:{id:999 }}, null, { transacting });
// respond with the receipt (don't forget to sanitize our output!)
return "worked"
}
catch(e){
return e
}
});
here, the id 999 already exists in the database, and it returns duplicated key error, however, the id 444 is inserted before this error and not removed when the transaction fails.
I also tried the following approach:
async transaction2(ctx){
const transacting = await strapi.db.connection.transaction();
try {
const fromUser = await strapi.query('api::local.local').create({ data:{id:444}}, null, { transacting });
const toUser = await strapi.query('api::local.local').create({ data:{id:999}}, null, { transacting });
await transacting.commit();
return "Deu"
} catch (err) {
await transacting.rollback();
console.log("ROLLBACK")
return err
}
}
The result is the same. When I call the rollback function, the first query is not reverted.
Any solution for this?