{"action":"opened","issue":{"url":"https://api.github.com/repos/SeyZ/jsonapi-serializer/issues/162","repository_url":"https://api.github.com/repos/SeyZ/jsonapi-serializer","labels_url":"https://api.github.com/repos/SeyZ/jsonapi-serializer/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/SeyZ/jsonapi-serializer/issues/162/comments","events_url":"https://api.github.com/repos/SeyZ/jsonapi-serializer/issues/162/events","html_url":"https://github.com/SeyZ/jsonapi-serializer/issues/162","id":283112744,"number":162,"title":"Why deserialize relationships into objects?","user":{"login":"JakeDluhy","id":6790323,"avatar_url":"https://avatars0.githubusercontent.com/u/6790323?v=4","gravatar_id":"","url":"https://api.github.com/users/JakeDluhy","html_url":"https://github.com/JakeDluhy","followers_url":"https://api.github.com/users/JakeDluhy/followers","following_url":"https://api.github.com/users/JakeDluhy/following{/other_user}","gists_url":"https://api.github.com/users/JakeDluhy/gists{/gist_id}","starred_url":"https://api.github.com/users/JakeDluhy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakeDluhy/subscriptions","organizations_url":"https://api.github.com/users/JakeDluhy/orgs","repos_url":"https://api.github.com/users/JakeDluhy/repos","events_url":"https://api.github.com/users/JakeDluhy/events{/privacy}","received_events_url":"https://api.github.com/users/JakeDluhy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-12-19T05:56:09Z","updated_at":"2017-12-19T05:56:09Z","closed_at":null,"author_association":"NONE","body":"I guess I don't get why the deserialization works the way it does. If I'm posting the body of an entity I want to create, any relationships that I post with it I would expect to be deserialized into a format that is convenient for foreign keys. Instead, I must include an `included` payload which will have the information of the relationship. I can see the use for easy validation, although tbh I think I'd still want to pull the database record in order to make sure my information is up-to-date. Here's an example of what I mean:\r\n\r\nI tried to send the payload\r\n```js\r\n{\r\n\t\"data\": {\r\n\t\t\"type\": \"moves\",\r\n\t\t\"attributes\": {\r\n\t\t\t\"from\": \"(-2)-(1)\",\r\n\t\t\t\"to\": \"(-1)-(1)\"\r\n\t\t},\r\n\t\t\"relationships\": {\r\n\t\t\t\"player-map\": {\r\n\t\t\t\t\"data\": {\r\n\t\t\t\t\t\"type\": \"player-maps\",\r\n\t\t\t\t\t\"id\": 1\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nWhich deserializes to\r\n```js\r\n{ from: '(-2)-(1)', to: '(-1)-(1)' }\r\n```\r\n\r\nInvestigating a little further, I realized I needed to add\r\n\r\n```js\r\n\"included\": [\r\n\t{\r\n\t\t\"type\": \"player-maps\",\r\n\t\t\"id\": 1\r\n\t}\r\n]\r\n```\r\n\r\nwhich deserializes to\r\n```js\r\n{ from: '(-2)-(1)', to: '(-1)-(1)', playerMap: { id: 1 } }\r\n```\r\n\r\nBut really, what I would like is to not have to add included, and have it automatically deserialize to\r\n```js\r\n{ from: '(-2)-(1)', to: '(-1)-(1)', playerMapId: 1 }\r\n```\r\nfor my foreign keys. I wrote a little function below to extract the data, so it's not a big deal, but I'm curious to hear the use case for deserializing to an object\r\n\r\n```js\r\nconst relObj = _.mapValues(\r\n      _.mapKeys(ctx.request.body.data.relationships, (val, key) => `${_.camelCase(key)}Id`),\r\n      (val) => _.get(val, 'data.id'),\r\n);\r\n```"}}
{"actor":{"display_login":"JakeDluhy"}}