Nextras\Orm\Relationships\HasOne::getEntity PHP Method

getEntity() public method

public getEntity ( $allowNull = false )
    public function getEntity($allowNull = false)
    {
        if ($this->value === false) {
            if (!$this->parent->isPersisted()) {
                $entity = null;
            } else {
                $collection = $this->getCachedCollection();
                $entity = $collection->getEntityIterator($this->parent)[0];
            }
            $this->set($entity, $allowNull);
        }
        if ($this->value === null && !$this->metadata->isNullable && !$allowNull) {
            throw new NullValueException($this->parent, $this->metadata);
        }
        return $this->value;
    }