Support for referencing entities without foreign keys
Author: PetrAdaCreated Mar 10, 2026Updated Jul 12, 2026
Labelspriority-lowwaiting-for-clarification
Describe the bug
I can write * @property ?File $image {m:1 File, oneSided=true}
but if the backing ID is an invalid value eg 22. and a record with the id 22 does not exist the HasOne object throws an exception even though the property is nullable.
Expected behavior NOT
abstract class HasOne implements IRelationshipContainer{
...
if (!$this->metadata->isNullable && !$allowNull) {
throw new NullValueException($this->metadata);
}
return null;
} elseif (is_scalar($entity)) {
return $this->getTargetRepository()->getByIdChecked($entity);
}
...
}YES
abstract class HasOne implements IRelationshipContainer{
...
if (!$this->metadata->isNullable && !$allowNull) {
throw new NullValueException($this->metadata);
}
return null;
} elseif (is_scalar($entity)) {
$repo = $this->getTargetRepository();
if ($this->metadata->isNullable || $allowNull) {
return $repo->getById($entity)
}
return $repo->getByIdChecked($entity);
}
...
}Versions::
- Database: [PERCONA]
- Orm: 3.0
- Dbal: Dbal 3.0
Source: nextras/orm