Nextras\Orm\Relationships\HasOne::createEntity PHP Метод

createEntity() защищенный Метод

protected createEntity ( $value, $allowNull )
    protected function createEntity($value, $allowNull)
    {
        if ($value instanceof IEntity) {
            if ($model = $this->parent->getModel(false)) {
                $repo = $model->getRepository($this->metadata->relationship->repository);
                $repo->attach($value);
            } elseif ($model = $value->getModel(false)) {
                $repository = $model->getRepositoryForEntity($this->parent);
                $repository->attach($this->parent);
            }
        } elseif ($value === null) {
            if (!$this->metadata->isNullable && !$allowNull) {
                throw new NullValueException($this->parent, $this->metadata);
            }
        } elseif (is_scalar($value)) {
            $value = $this->getTargetRepository()->getById($value);
        } else {
            throw new InvalidArgumentException('Value is not a valid entity representation.');
        }
        return $value;
    }