$BookTable->connection()->transactional(function()use($book, $BookTable, $order, $OrderTable, &$errorFlag) { $errorFlag[] = $BookTable->save($book); $errorFlag[] = $OrderTable->save($order); });
the second save if false,but it haven`t rollback.
$BookTable->connection()->transactional(function()use($book, $BookTable, $order, $OrderTable, &$errorFlag) { $errorFlag[] = $BookTable->save($book); $errorFlag[] = $OrderTable->save($order); });
the second save if false,but it haven`t rollback.
Transactions roll back when they raise an exception or return false, as stated in the docs. In your code, you are not returning anything so it assumes everything went well. You should return something like:
return $BookTable->save($book) && $OrderTable->save($order);
yes. i saw it in the docs. thank you !!! I sloved it and your code is better .