lib/components/types/Relationship.php
public function getRelatedObject($baseObject, $baseRole, $primaryRelation = null)
    {
        $companionRole = $this->companionRole($baseRole);
        $companionType = $this->companionRoleType($baseRole);
        $companionModel = $companionType->primaryModel;
        if (!isset($primaryRelation) || is_array($primaryRelation)) {
            if (!is_array($primaryRelation)) {
                $primaryRelation = [];
            }
            $primaryRelation = $this->getPrimaryRelation($baseObject, $baseRole, $primaryRelation);
        }
        if (!empty($primaryRelation)) {
            if ($companionRole === 'child') {
                return $primaryRelation->childObject;
            } else {
                return $primaryRelation->parentObject;
            }
        }

        return false;
    }
public function getRelatedObject($baseObject, $baseRole, $primaryRelation = null)
    {
        $companionRole = $this->companionRole($baseRole);
        $companionType = $this->companionRoleType($baseRole);
        $companionModel = $companionType->primaryModel;
        if (!isset($primaryRelation) || is_array($primaryRelation)) {
            if (!is_array($primaryRelation)) {
                $primaryRelation = [];
            }
            $primaryRelation = $this->getPrimaryRelation($baseObject, $baseRole, $primaryRelation);
        }
        if (!empty($primaryRelation)) {
            if ($companionRole === 'child') {
                return $primaryRelation->childObject;
            } else {
                return $primaryRelation->parentObject;
            }
        }

        return false;
    }
Get related object.

@param [[@doctodo param_type:baseObject]]      $baseObject      [[@doctodo param_description:baseObject]]
@param [[@doctodo param_type:baseRole]]        $baseRole        [[@doctodo param_description:baseRole]]
@param [[@doctodo param_type:primaryRelation]] $primaryRelation [[@doctodo param_description:primaryRelation]] [optional]

@return [[@doctodo return_type:getRelatedObject]] [[@doctodo return_description:getRelatedObject]]