nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
310 stars 57 forks source link

Explicit transaction spanning multiple flush() calls #191

Closed jkavalik closed 7 years ago

jkavalik commented 7 years ago

Currently even explicitly started transaction is commited during any flush() or xAndFlush() call which quite surprised me. Is there any way to not commit during the flush() and let the commit/rollback on the user? Or transaction stacking where you have to commit as many times as startTransaction for the commit to actually happen (and any rollback along the way would probably have to change the transaction to rollbackOnly)?

hrach commented 7 years ago

Yes, this seems to be very unpredictable and unusable when you want to manipulate with transation yourself.

hrach commented 7 years ago

@jkavalik could you please provide some sample of code with description what is current status and how would you expect it should work?

hrach commented 7 years ago

I have reviews the code and this issue and came to conclusion:

$connection->transactional(function() {
    $orm->persistAndFlush(...);
    ...
    $orm->persistAndFlush(...);
});

the aformentioned code will now result in correct transaction nesting:

  1. begin transaction
  2. savepoint xx
  3. release savepoint xx
  4. savepoint yy
  5. release savepoint yy
  6. commit

So, this is fixed in Nextras Dbal 3.0.