public function relation(string $propertyName) : RelationAliasDefiner
    {
        $this->verifyClassDefined(__METHOD__);
        $this->verifyMapperDefined(__METHOD__);

        if (!isset($this->relations[$propertyName])) {
            throw InvalidArgumentException::format(
                'Invalid property to load from parent %s: property must be mapped to a relation, \'%s\' given',
                $this->mapper->getObjectType(), $propertyName
            );
        }

        /** @var IToOneRelation $relation */
        $relation   = $this->relations[$propertyName];
        $definition = new self($this->orm);
        $definition->from($relation->getMapper());

        return new RelationAliasDefiner($definition, function ($alias, callable $relationReferenceLoader) use ($relation
        ) {
            if ($relation instanceof IToOneRelation) {
                $relation = $relation->withReference($relationReferenceLoader($relation));
            } elseif ($relation instanceof IToManyRelation) {
                $relation = $relation->withReference($relationReferenceLoader($relation));
            }

            if (is_string($alias)) {
                $relationDefiner = $this->readDefinition->relation($alias);
            } else {
                $relationDefiner = $this->readDefinition->accessorRelation(function () {
                }, $alias);
            }

            $relationDefiner->asCustom($relation);
            $this->loadRelationColumns($relation);
        });
    }
public function relation(string $propertyName) : RelationAliasDefiner
    {
        $this->verifyClassDefined(__METHOD__);
        $this->verifyMapperDefined(__METHOD__);

        if (!isset($this->relations[$propertyName])) {
            throw InvalidArgumentException::format(
                'Invalid property to load from parent %s: property must be mapped to a relation, \'%s\' given',
                $this->mapper->getObjectType(), $propertyName
            );
        }

        /** @var IToOneRelation $relation */
        $relation   = $this->relations[$propertyName];
        $definition = new self($this->orm);
        $definition->from($relation->getMapper());

        return new RelationAliasDefiner($definition, function ($alias, callable $relationReferenceLoader) use ($relation
        ) {
            if ($relation instanceof IToOneRelation) {
                $relation = $relation->withReference($relationReferenceLoader($relation));
            } elseif ($relation instanceof IToManyRelation) {
                $relation = $relation->withReference($relationReferenceLoader($relation));
            }

            if (is_string($alias)) {
                $relationDefiner = $this->readDefinition->relation($alias);
            } else {
                $relationDefiner = $this->readDefinition->accessorRelation(function () {
                }, $alias);
            }

            $relationDefiner->asCustom($relation);
            $this->loadRelationColumns($relation);
        });
    }
public function relation ( string $ propertyName ) : RelationAliasDefiner { $ this -> verifyClassDefined ( __METHOD__ ) ; $ this -> verifyMapperDefined ( __METHOD__ ) ; if ( ! isset ( $ this -> relations [ $ propertyName ] ) ) { throw InvalidArgumentException :: format ( 'Invalid property to load from parent %s: property must be mapped to a relation, \'%s\' given' , $ this -> mapper -> getObjectType ( ) , $ propertyName ) ; } /** @var IToOneRelation $relation */ $ relation = $ this -> relations [ $ propertyName ] ; $ definition = new self ( $ this -> orm ) ; $ definition -> from ( $ relation -> getMapper ( ) ) ; return new RelationAliasDefiner ( $ definition , function ( $ alias , callable $ relationReferenceLoader ) use ( $ relation ) { if ( $ relation instanceof IToOneRelation ) { $ relation = $ relation -> withReference ( $ relationReferenceLoader ( $ relation ) ) ; } elseif ( $ relation instanceof IToManyRelation ) { $ relation = $ relation -> withReference ( $ relationReferenceLoader ( $ relation ) ) ; } if ( is_string ( $ alias ) ) { $ relationDefiner = $ this -> readDefinition -> relation ( $ alias ) ; } else { $ relationDefiner = $ this -> readDefinition -> accessorRelation ( function ( ) { } , $ alias ) ; } $ relationDefiner -> asCustom ( $ relation ) ; $ this -> loadRelationColumns ( $ relation ) ; } ) ; }
Defines a relation to load.

@param string $propertyName

@return RelationAliasDefiner
@throws InvalidArgumentException
Defines a relation to load .