Ensure db is in transaction to commit or rollback.

This commit is contained in:
KJ 2024-06-02 11:31:37 -04:00
parent 701caae7eb
commit 91615c086d

View File

@ -72,9 +72,12 @@ class Model {
* *
* @return bool * @return bool
*/ */
public function beginTransaction(): bool public function rollBack(): bool
{ {
return static::db()->beginTransaction(); if ( static::db()->inTransaction())
return static::db()->rollBack();
else
return true;
} }
/** /**
@ -83,9 +86,12 @@ class Model {
* *
* @return bool * @return bool
*/ */
public function rollBack(): bool public function commit(): bool
{ {
return static::db()->rollBack(); if (static::db()->inTransaction())
return static::db()->commit();
else
return true;
} }
/** /**