{"action":"created","issue":{"url":"https://api.github.com/repos/confetti/yayson/issues/23","repository_url":"https://api.github.com/repos/confetti/yayson","labels_url":"https://api.github.com/repos/confetti/yayson/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/confetti/yayson/issues/23/comments","events_url":"https://api.github.com/repos/confetti/yayson/issues/23/events","html_url":"https://github.com/confetti/yayson/issues/23","id":121538622,"number":23,"title":"Store#toModel strips 'type' attributes","user":{"login":"magicpat","id":1121889,"avatar_url":"https://avatars.githubusercontent.com/u/1121889?v=3","gravatar_id":"","url":"https://api.github.com/users/magicpat","html_url":"https://github.com/magicpat","followers_url":"https://api.github.com/users/magicpat/followers","following_url":"https://api.github.com/users/magicpat/following{/other_user}","gists_url":"https://api.github.com/users/magicpat/gists{/gist_id}","starred_url":"https://api.github.com/users/magicpat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicpat/subscriptions","organizations_url":"https://api.github.com/users/magicpat/orgs","repos_url":"https://api.github.com/users/magicpat/repos","events_url":"https://api.github.com/users/magicpat/events{/privacy}","received_events_url":"https://api.github.com/users/magicpat/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-12-10T17:31:27Z","updated_at":"2016-02-08T08:34:34Z","closed_at":"2016-02-08T08:34:33Z","body":"So, this is a very specific use-case, which we currently need in our application, so I might be biased in my question here :-)\r\n\r\nCurrently we have a data-model for our json-api, for which the attribute 'type' is very important for rendering specific components (in react).\r\n\r\nI.e. you have tweets and a tweet may contain a sub-entity, which may be a link or another tweet (I call this json-api relationship 'sub_entity').\r\n\r\nNow I queried all my tweets with included `sub_entity`, but those `sub_entity` lost it's type, since the yayson `Store` does not add this attribute to the model. So I don't know if I should use my 'Link-Component' or 'Sub-Tweet-Component'.\r\n\r\n**What I got from Store#sync:**\r\n```\r\n{\r\n   id: 'tweet1',\r\n   sub_entity: {\r\n      'id': 'se1'\r\n   }\r\n}\r\n```\r\n\r\n**What I actually want from Store#sync:**\r\n```\r\n{\r\n  id: 'tweet1',\r\n  type: 'tweet',\r\n  sub_entity: {\r\n      'id': 'se1',\r\n      'type': 'link'\r\n  }\r\n}\r\n```\r\n\r\nThis design may be questionable, but our system is built kinda like that.\r\n\r\n**Second problem:**\r\n\r\nYayson currently wraps specific attributes in a get-function (i.e to wrap the links attribute).\r\nThis results of model objects being polluted with functions, although in my opinion, returned data should only consist of clean plain objects.\r\n\r\n\r\n**So, my temporary solution right now is:**\r\n\r\n* In the `Store#toModel` method, I add the type to the soon-to-return model\r\n  * https://github.com/runtastic/yayson/blob/temp-release/src/yayson/store.coffee#L20\r\n* Also, I added a constructor option for disabling the creation of  `get`-wrappers\r\n  * https://github.com/runtastic/yayson/blob/temp-release/src/yayson/store.coffee#L10\r\n  * Here the logic creating the `get`-fn: https://github.com/runtastic/yayson/blob/temp-release/src/yayson/store.coffee#L47-L49\r\n  * This is designed as opt-out, that means it doesn't break currently existing code\r\n\r\nNow, with my current implementation, I can use the store like in this green test-case:\r\nhttps://github.com/runtastic/yayson/blob/temp-release/test/yayson/store.coffee#L112-L139\r\n\r\n\r\n**My concrete questions to you are:**\r\n\r\n* Is there any specific reason for the type not to be included in the returned denormalized model?\r\n* Is there a specific use-case why we need the `get`-function? (although I made this optional, it is not too important)\r\n\r\n\r\nI hope you understand my problem and maybe you find this code changes helpful, if so I will be happy to create a PR :-)"},"comment":{"url":"https://api.github.com/repos/confetti/yayson/issues/comments/181254701","html_url":"https://github.com/confetti/yayson/issues/23#issuecomment-181254701","issue_url":"https://api.github.com/repos/confetti/yayson/issues/23","id":181254701,"user":{"login":"jede","id":7389,"avatar_url":"https://avatars.githubusercontent.com/u/7389?v=3","gravatar_id":"","url":"https://api.github.com/users/jede","html_url":"https://github.com/jede","followers_url":"https://api.github.com/users/jede/followers","following_url":"https://api.github.com/users/jede/following{/other_user}","gists_url":"https://api.github.com/users/jede/gists{/gist_id}","starred_url":"https://api.github.com/users/jede/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jede/subscriptions","organizations_url":"https://api.github.com/users/jede/orgs","repos_url":"https://api.github.com/users/jede/repos","events_url":"https://api.github.com/users/jede/events{/privacy}","received_events_url":"https://api.github.com/users/jede/received_events","type":"User","site_admin":false},"created_at":"2016-02-08T08:34:33Z","updated_at":"2016-02-08T08:34:33Z","body":"Thanks! Great feedback, I'll make sure to add the type!"}}