This commit is contained in:
2023-08-25 10:01:53 +08:00
parent 5caed72909
commit 703300182b
+9 -5
View File
@@ -434,16 +434,20 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
{
[$sql, $param] = SqlBuilder::builder(static::query())->insert($this->_attributes);
$dbConnection = $this->getConnection()->createCommand($sql, $param);
$connection = $this->getConnection()->beginTransaction();
$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;
}
return $this;
}
if ($this->hasPrimary()) {
$this->_attributes[$this->getPrimary()] = $lastId;
}
return $this;
}