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);