From 42d4a6f79d07180e9050b658dcc79d7655d36af4 Mon Sep 17 00:00:00 2001 From: Aleksey Grunin <49051631+avegacms@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:19:59 +0600 Subject: [PATCH 1/2] Fix bug #8806 Bug: when the query ($this->first()) result returns NULL we get TypeError --- system/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Model.php b/system/Model.php index b3ecfc653943..c4ca9b6cc6e9 100644 --- a/system/Model.php +++ b/system/Model.php @@ -318,7 +318,7 @@ protected function doFirst() $row = $builder->limit(1, 0)->get()->getFirstRow($this->tempReturnType); - if ($useCast) { + if ($useCast && $row !== null) { $row = $this->convertToReturnType($row, $returnType); $this->tempReturnType = $returnType; From 17439a32f96d71b0bb20f65df7fe29f0c0dc630b Mon Sep 17 00:00:00 2001 From: Aleksey Grunin <49051631+avegacms@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:21:27 +0600 Subject: [PATCH 2/2] Update Model.php Fix TypeError error in the methods: doFind and doFirst when using casts --- system/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Model.php b/system/Model.php index c4ca9b6cc6e9..03ca7525ec76 100644 --- a/system/Model.php +++ b/system/Model.php @@ -210,7 +210,7 @@ protected function doFind(bool $singleton, $id = null) $row = $builder->get()->getResult($this->tempReturnType); } - if ($useCast) { + if ($useCast && $row !== null) { $row = $this->convertToReturnType($row, $returnType); $this->tempReturnType = $returnType;