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);
    }
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);
    }
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 ) ; }
NeoMerx override to generate belongsTo and hasMany links
inside `relationships` node.

belongsTo example: /cultures?country_id=1
hasMany example"   /countries/1/relationships/currency"

@param \Cake\Datasource\EntityInterface $entity Entity
@param string $name Relationship name in lowercase singular or plural
@param array $meta Optional array with meta information
@param bool $treatAsHref True to NOT prefix url

@return \Neomerx\JsonApi\Document\Link
NeoMerx override to generate belongsTo and hasMany links inside relationships node .