- RelationBuilder now returns NULL if no entity were found AND given field is nullable

This commit is contained in:
Dave Mc Nicoll 2024-10-14 16:07:12 +00:00
parent 3c2ae86653
commit 573d4cc06b
1 changed files with 7 additions and 1 deletions

View File

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