nilportugues / php-json-api

JSON API transformer outputting valid (PSR-7) API Responses.
http://nilportugues.com
MIT License
71 stars 35 forks source link

URL generation should attempt to use id value from class/alias if translation failed #38

Closed nilportugues closed 8 years ago

nilportugues commented 8 years ago

Hard title, easy to explain.

Given a mapping User, with name user as the type in the response, and a url template being /user/{user}/edit... mapping to the id field (that being a class property named id or user_id) will fail.

Yet, it is possible to guess that is the type is user, and user is in the url, the value should be the id's, as we are following a convention.

This should be done as a second pass, after applying the id fields for the URL generation and getting the same result and before disregarding the URL.

nilportugues commented 8 years ago

https://github.com/nilportugues/jsonapi-transformer/blob/a162d369ae70afed90e6d944be4523a9920163b7/src/Helpers/DataLinksHelper.php