-
Notifications
You must be signed in to change notification settings - Fork 40
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
Relationships normalization #11
Comments
Instead of additional type, we can serialize ids as |
@apsavin with this solution, we loose the ability to compare I agree this is a more elegant solution, but the library seems to be coded with this is mind. The documentation explicit it as a feature. Waiting for @yury-dymov suggestion :) |
Ok understood. Serialize ids as a string containings brackets. The updated proposal:
For the point 2 of empty relationships we can have:
Or
|
Hi @lvauvillier, From my experience, the problem is not with json-api-normalizer but with JSON API in the first place. My JA provider returns collection as an object if backend provides only one object. If this is different in general, please let me know. To give me a context, please attach your JSON API document, so I could figure out if json-api-normalizer can be improved or it is an issue of JSON API itself. To resolve this issue in my project I used function wrap(object) {
if (isArray(object) || isNull(object) || isUndefined(object)) {
return object;
}
return [object];
} |
The jsonapi spec indicates that the data field of a relationship is a resource linkage
And
If your JA provider has a different strategy, the proposal didn't break the current implementation but makes the library closer to the spec. Also, the spec doesn't specify any constraint to have the same object type in a collection. [edited] New proposal, following exactly the spec (but not backward compatible):
|
Ok, I see. Will deliver update by the end of the week for both redux-object and json-api-normalizer. PRs are also welcome :) |
Just submit a PR. Finally, the normalized relationship shape is very similar to the original. I just add the case of camelizeKeys option. I keep
|
Thank you! Super busy now, will review till the end on the day (PST). |
closed via PR |
Hi Yury,
I'm facing new problems with the relationships normalization:
Data representation feature
With
The data repesentation feature
of one-to-many relationship, we lost the type "collection" if the collection contains only one element. I have some issues here with theredux-object
build function. The single element collection builded is an object instead of an array containing one object.I agree the fact data representation as a string is useful in a redux context. A naive approach can be adding a new special key to the metas to know the type of the relation (object or collection).
I'm not confident to add a special key to store it... but there is some examples to show how it can be represented:
The
redux-object
has also to be updated to understand these new properties.Empty relationships
If a relationship has no data (null) or an empty collection ([]) and links, only the links will be normalized. We lost here the fact that the relation points to an empty data or collection. The
redux-object
build will raise a lazy loading error when we want to access the relationship. Even if we know there is no data to return.Following the precedent naive approach, i suggest to store only the collection type:
The
redux-object
has also to be updated to understand that the data is already loaded and not try to lazy load something.I'm currently working on a prototype with this approach, but if you had any suggestions or direction, I'll follow it and submit a PR for the community.
The text was updated successfully, but these errors were encountered: