Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Uses cases for doctrine nested transactions

$
0
0

I have a project where I need to do a transaction because I have 3 entities that depend on each other. Tenant, Organization, User.First I started with a single transaction on one of the repositories and then I found out about doctrine nested transactions.I didn't quite understand their role in doctrine and what are the use cases.Can you explain me in more details than their documentation what are the use cases and if it applies to my case ?

In my case User requires an Organization id, Tenant id and Organization requires an Tenant id.If on create one of the entities fails from some motive it should fail all three and rollback.

Example from documentation of a nested transaction:

<?php// $conn instanceof Doctrine\DBAL\Connection$conn->beginTransaction(); // 0 => 1, "real" transaction startedtry {    ...    // nested transaction block, this might be in some other API/library code that is    // unaware of the outer transaction.    $conn->beginTransaction(); // 1 => 2    try {        ...        $conn->commit(); // 2 => 1    } catch (\Exception $e) {        $conn->rollBack(); // 2 => 1, transaction marked for rollback only        throw $e;    }    ...    $conn->commit(); // 1 => 0, "real" transaction committed} catch (\Exception $e) {    $conn->rollBack(); // 1 => 0, "real" transaction rollback    throw $e;}

Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>