From a10a84c693aba10f7368a0a401cbb764b23044bf Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 28 May 2024 10:22:32 +0700 Subject: [PATCH] Improve performance --- src/AbstractActiveRecord.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/AbstractActiveRecord.php b/src/AbstractActiveRecord.php index 21ef22c02..a3a40cfbc 100644 --- a/src/AbstractActiveRecord.php +++ b/src/AbstractActiveRecord.php @@ -190,10 +190,8 @@ public function getOldPrimaryKey(bool $asArray = false): mixed ); } - if (count($keys) === 1) { - $key = $this->oldAttributes[$keys[0]] ?? null; - - return $asArray ? [$keys[0] => $key] : $key; + if ($asArray === false && count($keys) === 1) { + return $this->oldAttributes[reset($keys)] ?? null; } $values = []; @@ -209,8 +207,8 @@ public function getPrimaryKey(bool $asArray = false): mixed { $keys = $this->primaryKey(); - if (count($keys) === 1) { - return $asArray ? [$keys[0] => $this->getAttribute($keys[0])] : $this->getAttribute($keys[0]); + if ($asArray === false && count($keys) === 1) { + return $this->getAttribute(reset($keys)); } $values = [];