{"action":"closed","issue":{"url":"https://api.github.com/repos/beauby/jsonapi-datastore/issues/12","labels_url":"https://api.github.com/repos/beauby/jsonapi-datastore/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/beauby/jsonapi-datastore/issues/12/comments","events_url":"https://api.github.com/repos/beauby/jsonapi-datastore/issues/12/events","html_url":"https://github.com/beauby/jsonapi-datastore/issues/12","id":115391203,"number":12,"title":"store crashes when serializing null relationship","user":{"login":"jamesdixon","id":110114,"avatar_url":"https://avatars.githubusercontent.com/u/110114?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesdixon","html_url":"https://github.com/jamesdixon","followers_url":"https://api.github.com/users/jamesdixon/followers","following_url":"https://api.github.com/users/jamesdixon/following{/other_user}","gists_url":"https://api.github.com/users/jamesdixon/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesdixon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesdixon/subscriptions","organizations_url":"https://api.github.com/users/jamesdixon/orgs","repos_url":"https://api.github.com/users/jamesdixon/repos","events_url":"https://api.github.com/users/jamesdixon/events{/privacy}","received_events_url":"https://api.github.com/users/jamesdixon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-05T22:37:26Z","updated_at":"2015-11-06T00:12:38Z","closed_at":"2015-11-06T00:12:38Z","body":"When attempting to serialize an object with a `null` relationship, the `serialize()` method crashed. I was going to make a PR, but my fork is already a bit customized to serialize the store to an object that doesn't contain any of the store methods so I can pass it to my ORM. \r\n\r\nThat said, I've tracked the issue down to [this line](https://github.com/beauby/jsonapi-datastore/blob/master/src/jsonapi-datastore.js#L47). Essentially, `self[key]` is `undefined` when a `null` relationship is serialized, which causes the crash. This bit of code appears to fix it:\r\n\r\n```javascript\r\n    if (self[key]) {\r\n        if (self[key].constructor === Array) {\r\n          res.data.relationships[key] = {\r\n            data: self[key].map(relationshipIdentifier)\r\n          };\r\n        } else {\r\n          res.data.relationships[key] = {\r\n            data: relationshipIdentifier(self[key])\r\n          };\r\n        }\r\n      } else {\r\n        res.data.relationships[key] = null;\r\n      }\r\n```\r\n\r\nI haven't fully tested, but just wanted to give a heads up. Thanks for building a great library!"}}