/** * @param Property $property * @param Relationship\HasOne $relationship micro-optimalization * @param Filtering|null $filtering * @throws InvalidValueException * @return Entity */ private function getHasOneValue(Property $property, Relationship\HasOne $relationship, Filtering $filtering = null) { $targetTable = $relationship->getTargetTable(); $row = $this->row->referenced($targetTable, $relationship->getColumnReferencingTargetTable(), $filtering); if ($row === null) { if (!$property->isNullable()) { $name = $property->getName(); throw new InvalidValueException("Property '{$name}' cannot be null in entity " . get_called_class() . '.'); } return null; } else { $entityClass = $this->mapper->getEntityClass($targetTable, $row); $entity = $this->entityFactory->createEntity($entityClass, $row); $this->checkConsistency($property, $entityClass, $entity); $entity->makeAlive($this->entityFactory); return $entity; } }