From c5576d94b45246989269fc027ba3949dbe1b69ee Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 30 Sep 2023 12:02:19 +0900 Subject: [PATCH] fix: toRawArray() behavior The previous code no longer makes sense. --- system/Entity/Entity.php | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/system/Entity/Entity.php b/system/Entity/Entity.php index 969b198c9fb2..6a06ca3c3ad1 100644 --- a/system/Entity/Entity.php +++ b/system/Entity/Entity.php @@ -204,7 +204,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu } /** - * Returns the raw values of the current attributes. + * Returns the values for database of the current attributes. * * @param bool $onlyChanged If true, only return values that have changed since object creation * @param bool $recursive If true, inner entities will be cast as array as well. @@ -213,41 +213,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu */ public function toRawArray(bool $onlyChanged = false, bool $recursive = false): array { - $return = []; - - if (! $onlyChanged) { - if ($recursive) { - return array_map(static function ($value) use ($onlyChanged, $recursive) { - if ($value instanceof self) { - $value = $value->toRawArray($onlyChanged, $recursive); - } elseif (is_callable([$value, 'toRawArray'])) { - $value = $value->toRawArray(); - } - - return $value; - }, $this->attributes); - } - - return $this->attributes; - } - - foreach ($this->attributes as $key => $value) { - if (! $this->hasChanged($key)) { - continue; - } - - if ($recursive) { - if ($value instanceof self) { - $value = $value->toRawArray($onlyChanged, $recursive); - } elseif (is_callable([$value, 'toRawArray'])) { - $value = $value->toRawArray(); - } - } - - $return[$key] = $value; - } - - return $return; + return $this->toDatabase($onlyChanged, $recursive); } /**