From 573d4cc06b99f5b09d1f0938baa53f7b12ad7e86 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 14 Oct 2024 16:07:12 +0000 Subject: [PATCH] - RelationBuilder now returns NULL if no entity were found AND given field is nullable --- src/Repository/RelationBuilder.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Repository/RelationBuilder.php b/src/Repository/RelationBuilder.php index 4fa2f1d..07f6c76 100644 --- a/src/Repository/RelationBuilder.php +++ b/src/Repository/RelationBuilder.php @@ -109,7 +109,13 @@ class RelationBuilder $this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository); - return call_user_func([ $this->repository, $relation->function() ]) ?? $this->instanciateEmptyEntity($name, $relation); + $value = call_user_func([ $this->repository, $relation->function() ]) ?? null; + + if ($value === null && $this->resolver->reflectedClass->getProperties(true)[$name]->allowsNull()) { + return null; + } + + return $value ?? $this->instanciateEmptyEntity($name, $relation); case $relation->isOneToMany(): $this->oneToMany($name, $relation);