-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an extension point in JSONSerializer to determine which hasMany relationships should be serialized #2494
Comments
In ember-data the hasMany array should not be a normal array but the end result of a query over the belongsTo items. (just as on the backend) |
cc @sly7-7 I think you are handling this |
If we consider adding |
@sly7-7 Looking forward to it. |
I am still a beginner and new to this kind of testing. I updated my old, not working with hashMany, project: When {serialize: true} works pages should be filled if you select "test4": |
@sly7-7 I have converted my old test https://github.com/broerse/ember-select-test but get |
More about this error: #3373 |
I would say yes. Wanna get someone to make a PR and feature flag it? |
For clarification @igorT is suggesting we make |
Closing this since |
A frequently brought up issue (#2068, #1678, 7f752ad, to name a few) is the fact that
JSONSerializer#serializeHasMany
does not serializemanyToOne
(i.e., bidirectional) hasMany relationships. It is clear from the discussion elsewhere that this is a considered behavior and won't be changed.The 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.However, 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, ember-indexeddb-adapter, in my own app using ember-pouch) is to copy
serializeHasMany
fromDS.JSONSerializer
into the application's serializer and addmanyToOne
to the list of relationships to be serialized.This 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.
I'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?[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.
The text was updated successfully, but these errors were encountered: