{"action":"created","issue":{"url":"https://api.github.com/repos/emberjs/data/issues/2494","labels_url":"https://api.github.com/repos/emberjs/data/issues/2494/labels{/name}","comments_url":"https://api.github.com/repos/emberjs/data/issues/2494/comments","events_url":"https://api.github.com/repos/emberjs/data/issues/2494/events","html_url":"https://github.com/emberjs/data/issues/2494","id":49490002,"number":2494,"title":"Provide an extension point in JSONSerializer to determine which hasMany relationships should be serialized","user":{"login":"rsutphin","id":2503,"avatar_url":"https://avatars.githubusercontent.com/u/2503?v=3","gravatar_id":"","url":"https://api.github.com/users/rsutphin","html_url":"https://github.com/rsutphin","followers_url":"https://api.github.com/users/rsutphin/followers","following_url":"https://api.github.com/users/rsutphin/following{/other_user}","gists_url":"https://api.github.com/users/rsutphin/gists{/gist_id}","starred_url":"https://api.github.com/users/rsutphin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsutphin/subscriptions","organizations_url":"https://api.github.com/users/rsutphin/orgs","repos_url":"https://api.github.com/users/rsutphin/repos","events_url":"https://api.github.com/users/rsutphin/events{/privacy}","received_events_url":"https://api.github.com/users/rsutphin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-11-20T04:11:00Z","updated_at":"2015-06-10T22:03:51Z","closed_at":null,"body":"A frequently brought up issue (#2068, #1678, 7f752ad15e, to name a few) is the fact that `JSONSerializer#serializeHasMany` does not serialize `manyToOne` (i.e., bidirectional) hasMany relationships. It is clear from the discussion elsewhere that this is a considered behavior and won't be changed.\r\n\r\nThe recommended alternative is to use `EmbeddedRecordsMixin` in a custom serializer for each model to indicate which hasManys should be serialized. If you only want some bidrectional hasManys to be treated this way this seems like a fine solution.\r\n\r\nHowever, if you want to serialize _all_ hasMany relationships[1], it adds complexity and cognitive load — every time you add a new hasMany relationship, you have to remember add it to a serializer somewhere else also. So practically, the solution that is used (e.g., in [ember-localstorage-adapter][LS], [ember-indexeddb-adapter][IDB], in my own app using ember-pouch) is to copy `serializeHasMany` from `DS.JSONSerializer` into the application's serializer and add `manyToOne` to the list of relationships to be serialized.\r\n\r\n[LS]: https://github.com/kurko/ember-localstorage-adapter/blob/c32477626ce0e7c8447e1ee79eb78e64a8357d70/localstorage_adapter.js#L6\r\n[IDB]: https://github.com/kurko/ember-indexeddb-adapter/blob/0b1c73a1134606ccc9dfc1aadb86af5b4dd9fe4d/packages/indexeddb-adapter/lib/indexeddb_serializer.js#L2\r\n\r\nThis is less than ideal for all the reasons that copying and pasting code is always less than ideal. It would be great if JSONSerializer could provide an extension point that a customized serializer could use to indicate which hasMany associations should be serialized by default, without requiring that the rest of the implementation be copied also.\r\n\r\nI'd be happy to write a PR for this. Question: are the values returned by `determineRelationshipType` considered part of the public API for ember-data and therefore unlikely to change?\r\n\r\n[1]: One reason you'd want to do this that I'm aware of is if your read and write formats are the same. This happens for sure when you are writing to a local document store, like PouchDB or IndexedDB.\r\n"},"comment":{"url":"https://api.github.com/repos/emberjs/data/issues/comments/110930165","html_url":"https://github.com/emberjs/data/issues/2494#issuecomment-110930165","issue_url":"https://api.github.com/repos/emberjs/data/issues/2494","id":110930165,"user":{"login":"broerse","id":1432898,"avatar_url":"https://avatars.githubusercontent.com/u/1432898?v=3","gravatar_id":"","url":"https://api.github.com/users/broerse","html_url":"https://github.com/broerse","followers_url":"https://api.github.com/users/broerse/followers","following_url":"https://api.github.com/users/broerse/following{/other_user}","gists_url":"https://api.github.com/users/broerse/gists{/gist_id}","starred_url":"https://api.github.com/users/broerse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broerse/subscriptions","organizations_url":"https://api.github.com/users/broerse/orgs","repos_url":"https://api.github.com/users/broerse/repos","events_url":"https://api.github.com/users/broerse/events{/privacy}","received_events_url":"https://api.github.com/users/broerse/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T22:03:51Z","updated_at":"2015-06-10T22:03:51Z","body":"I am still a beginner and new to this kind of testing. I updated my old, not working with hashMany, project:\r\nhttps://github.com/broerse/ember-select-test\r\nand have to work on some deprecations but how do I get the new patch in bower? It fails now.\r\n\r\nWhen {serialize: true} works pages should be filled if you select \"test4\":\r\nhttp://martinic.iriscouch.com/_utils/document.html?selecttest/modelname_2_9D69343F-6FF0-BB4F-AF87-82074E9CF99B"}}