From 2ee482241de8d3ce51c39f5c907632b5e6c0b9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 1 Sep 2023 10:53:38 +0800 Subject: [PATCH] eee --- Base/Model.php | 8 ++------ Connection.php | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Base/Model.php b/Base/Model.php index 0f62c5d..8c4c91f 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -434,15 +434,13 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T { [$sql, $param] = SqlBuilder::builder(static::query())->insert($this->_attributes); - $connection = $this->getConnection()->beginTransaction(); + $connection = $this->getConnection(); $dbConnection = $connection->createCommand($sql, $param); $lastId = $dbConnection->save(); if ($lastId === false) { - $connection->rollback(); return false; } else { - $connection->commit(); if ($this->hasPrimary()) { $this->_attributes[$this->getPrimary()] = $lastId; } @@ -469,13 +467,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T return false; } - $connection = $this->getConnection()->beginTransaction(); + $connection = $this->getConnection(); $command = $connection->createCommand($generate, $query->attributes); if ($command->save()) { - $connection->commit(); return $this->refresh()->afterSave($old, $change); } else { - $connection->rollback(); return FALSE; } } diff --git a/Connection.php b/Connection.php index a6d3219..4529d70 100644 --- a/Connection.php +++ b/Connection.php @@ -282,7 +282,7 @@ class Connection extends Component if ($pdo === null) { throw new Exception('Failed to rollback transaction: connection was exists.'); } - if ($pdo->inTransaction()) { + if ($this->inTransaction()) { $pdo->rollback(); } $this->release($pdo); @@ -301,7 +301,7 @@ class Connection extends Component if ($pdo === null) { throw new Exception('Failed to commit transaction: connection was exists.'); } - if ($pdo->inTransaction()) { + if ($this->inTransaction()) { $pdo->commit(); } $this->release($pdo);