public function getRelationshipSelfLink($entity, $name, $meta = null, $treatAsHref = false)
    {
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            $name = Inflector::underscore($name);
        }

        $association = $this->_repository->associations()->getByProperty($name);
        $relatedRepository = $association->getTarget();

        // generate link for belongsTo relationship
        if (in_array($association->type(), [Association::MANY_TO_ONE, Association::ONE_TO_ONE])) {
            if ($this->_view->viewVars['_jsonApiBelongsToLinks'] === true) {
                list(, $controllerName) = pluginSplit($this->_repository->getRegistryAlias());
                $sourceName = Inflector::underscore(Inflector::singularize($controllerName));

                $url = Router::url($this->_getRepositoryRoutingParameters($relatedRepository) + [
                    '_method' => 'GET',
                    'action' => 'view',
                    $sourceName . '_id' => $entity->id,
                    'from' => $this->_repository->getRegistryAlias(),
                    'type' => $name,
                ], $this->_view->viewVars['_absoluteLinks']);
            } else {
                $name = Inflector::dasherize($name);
                $relatedEntity = $entity[$name];

                $url = Router::url($this->_getRepositoryRoutingParameters($relatedRepository) + [
                    '_method' => 'GET',
                    'action' => 'view',
                    $relatedEntity->get($relatedRepository->getPrimaryKey()),
                ], $this->_view->viewVars['_absoluteLinks']);
            }

            return new Link($url, $meta, $treatAsHref);
        }

        // generate the link for hasMany relationship
        $foreignKey = $association->getForeignKey();
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            $foreignKey = Inflector::dasherize($foreignKey);
        }

        $url = Router::url($this->_getRepositoryRoutingParameters($relatedRepository) + [
            '_method' => 'GET',
            'action' => 'index',
            '?' => [$foreignKey => $entity->id]
        ], $this->_view->viewVars['_absoluteLinks']);

        return new Link($url, $meta, $treatAsHref);
    }