code: public function getPrimaryRelation($baseObject, $baseRole, $relationOptions = [])
      {
          $companionRole = $this->companionRole($baseRole);
          $companionType = $this->companionRoleType($baseRole);
          $companionModel = $companionType->primaryModel;
          if (!isset($relationOptions['order'])) {
              $relationOptions['order'] = [];
          }
          if ($companionRole === 'child') {
              array_unshift($relationOptions['order'], ['primary_child', SORT_DESC]);
              $relation = $baseObject->queryParentRelations($companionModel, $relationOptions)->one();
          } else {
              array_unshift($relationOptions['order'], ['primary_parent', SORT_DESC]);
              $relation = $baseObject->queryParentRelations($companionModel, $relationOptions)->one();
          }
          if (empty($relation)) {
              return false;
          } else {
              return $relation;
          }
      }
docs: Get primary relation.
  
  @param [[@doctodo param_type:baseObject]] $baseObject      [[@doctodo param_description:baseObject]]
  @param [[@doctodo param_type:baseRole]]   $baseRole        [[@doctodo param_description:baseRole]]
  @param array                              $relationOptions [[@doctodo param_description:relationOptions]] [optional]
  
  @return [[@doctodo return_type:getPrimaryRelation]] [[@doctodo return_description:getPrimaryRelation]]