diff --git a/src/LeanOrm/DBConnector.php b/src/LeanOrm/DBConnector.php index c3152e1..213d411 100644 --- a/src/LeanOrm/DBConnector.php +++ b/src/LeanOrm/DBConnector.php @@ -306,7 +306,7 @@ public function getConnectionName(): string { * * @return mixed result of the query or false on failure or if there are no rows */ - public function dbFetchOne(string $select_query, array $parameters = [] ) { + public function dbFetchOne(string $select_query, array $parameters = [] ): mixed { $result = static::_execute($select_query, $parameters, true, $this->connection_name); /** @psalm-suppress PossiblyInvalidArrayAccess */ diff --git a/src/LeanOrm/Model.php b/src/LeanOrm/Model.php index 9478d1c..9623b34 100644 --- a/src/LeanOrm/Model.php +++ b/src/LeanOrm/Model.php @@ -1017,7 +1017,11 @@ protected function loadHasOne( * @psalm-suppress MixedArrayOffset * @psalm-suppress MixedMethodCall */ - $parent_data[$p_rec_key]->setRelatedData($rel_name, $matching_related_rows[0]); + $parent_data[$p_rec_key]->setRelatedData( + $rel_name, + (\count($matching_related_rows) > 0) + ? $matching_related_rows[0] : [] + ); } else { @@ -1031,8 +1035,11 @@ protected function loadHasOne( * @psalm-suppress MixedArrayOffset * @psalm-suppress MixedArrayAssignment * @psalm-suppress MixedArgument + * @psalm-suppress PossiblyInvalidArgument */ - $parent_data[$p_rec_key][$rel_name] = $matching_related_rows[0]; + $parent_data[$p_rec_key][$rel_name] = + (\count($matching_related_rows) > 0) + ? $matching_related_rows[0] : []; } } // foreach( $parent_data as $p_rec_key => $parent_record ) @@ -1050,7 +1057,10 @@ protected function loadHasOne( //stitch the related data to the parent record /** @psalm-suppress MixedArgument */ - $parent_data->setRelatedData($rel_name, array_shift($related_data)); + $parent_data->setRelatedData( + $rel_name, + (\count($related_data) > 0) ? \array_shift($related_data) : [] + ); } // else if ($parent_data instanceof \GDAO\Model\RecordInterface) } // if( array_key_exists($rel_name, $this->relations) ) }