Last active
June 3, 2019 09:16
-
-
Save willviles/d4cc3fe6b3c8fccb99d9aa0374d75740 to your computer and use it in GitHub Desktop.
JSON:API relationships vs nested attributes. Only return records as relationships to the frontend if we need to do CRUD operations on them, otherwise we'll have too many unnecessary models in memory!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "data": [{ | |
| "type": "properties", | |
| "id": "1", | |
| "attributes": { | |
| "geolocation": "xx,xx", | |
| "propertyInfos": [{ | |
| "id": "123", | |
| "value": "Shitface bastards", | |
| "locale": "en-gb", | |
| "info": { | |
| "id": "description-of-owners", | |
| "name": "Description of Owners", | |
| "localization": "Description of Owners" | |
| } | |
| }] | |
| } | |
| }] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "data": [{ | |
| "type": "properties", | |
| "id": "1", | |
| "attributes": { | |
| "geolocation": "xx,xx" | |
| }, | |
| "relationships": { | |
| "propertyInfo": { | |
| "data": [{"id": "123", "type": "propertyInfos"}] | |
| } | |
| } | |
| }], | |
| "included": [ | |
| { | |
| "type": "propertyInfos", | |
| "id": "123", | |
| "attributes": { | |
| "value": "Shitface bastards", | |
| "locale": "en-gb" | |
| }, | |
| "relationships": { | |
| "property": { | |
| "data": {"id": "1", "type": "properties"} | |
| }, | |
| "info": { | |
| "data": {"id": "description-of-owners", "type": "infos"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "infos", | |
| "id": "description-of-owners", | |
| "attributes": { | |
| "name": "Description of Owners", | |
| "localization": "Description of Owners" | |
| } | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment