LeanMapper\Entity::getBelongsToOneValue PHP Метод

getBelongsToOneValue() приватный Метод

private getBelongsToOneValue ( Property $property, LeanMapper\Relationship\BelongsToOne $relationship, Filtering $filtering = null ) : Entity
$property LeanMapper\Reflection\Property
$relationship LeanMapper\Relationship\BelongsToOne micro-optimalization
$filtering Filtering
Результат Entity
    private function getBelongsToOneValue(Property $property, Relationship\BelongsToOne $relationship, Filtering $filtering = null)
    {
        $targetTable = $relationship->getTargetTable();
        $rows = $this->row->referencing($targetTable, $relationship->getColumnReferencingSourceTable(), $filtering, $relationship->getStrategy());
        $count = count($rows);
        if ($count > 1) {
            throw new InvalidValueException('There cannot be more than one entity referencing to entity ' . get_called_class() . " in property '{$property->getName()}' with m:belongToOne relationship.");
        } elseif ($count === 0) {
            if (!$property->isNullable()) {
                $name = $property->getName();
                throw new InvalidValueException("Property '{$name}' cannot be null in entity " . get_called_class() . '.');
            }
            return null;
        } else {
            $row = reset($rows);
            $entityClass = $this->mapper->getEntityClass($targetTable, $row);
            $entity = $this->entityFactory->createEntity($entityClass, $row);
            $this->checkConsistency($property, $entityClass, $entity);
            $entity->makeAlive($this->entityFactory);
            return $entity;
        }
    }