File tree Expand file tree Collapse file tree
user_guide_src/source/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -791,13 +791,15 @@ the transaction status fails without an exception, ``false`` is returned.
791791Existing Model query constraints are applied to the locked lookup, so methods
792792like ``where() `` and ``withDeleted() `` can be called before ``withLockedRow() ``.
793793
794- Any exception thrown by the callback rolls back the transaction and is rethrown.
795- Unsupported lock combinations throw the same database exceptions as
796- ``lockForUpdate() ``.
797-
798- The locked row is reloaded directly from the database, so Model find callbacks
799- are not run for that lookup. Model methods called inside the callback, such as
800- ``save() `` or ``update() ``, still follow the Model's callback setting.
794+ Returning ``false `` from the callback does not trigger a rollback. To explicitly
795+ roll back from the callback, throw an exception. Any exception thrown by the
796+ callback rolls back the transaction and is rethrown. Unsupported lock
797+ combinations throw the same database exceptions as ``lockForUpdate() ``.
798+
799+ .. important :: The locked row is reloaded directly from the database, so Model
800+ find callbacks are not run for that lookup. Model methods called inside the
801+ callback, such as ``save() `` or ``update() ``, still follow the Model's
802+ callback setting.
801803
802804.. note :: Row locks are only useful when the database supports transactions and
803805 pessimistic locks. See :ref: `query-builder-lock-for-update ` for driver
Original file line number Diff line number Diff line change 33$ result = $ accountModel ->withLockedRow ($ id , static function (object $ account , $ model ): bool {
44 $ account ->balance -= 100 ;
55
6- return $ model ->save ($ account );
6+ if (! $ model ->save ($ account )) {
7+ throw new RuntimeException ('Unable to save the account. ' );
8+ }
9+
10+ return true ;
711});
You can’t perform that action at this time.
0 commit comments