Relationships normalization
See original GitHub issueHi 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 the redux-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:
- Collection with a single object
relationships: {
comments: {
__relation_type: 'collection',
id: '295',
type: 'question'
}
}
- Collection with multiple objects
relationships: {
comments: {
__relation_type: 'collection',
id: '295,678',
type: 'question'
}
}
- Object relationship
relationships: {
author: {
__relation_type: 'object',
id: '23',
type: 'author'
}
}
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:
relationships: {
author: {
__relation_type: 'object',
}
}
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.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top GitHub Comments
Ok, I see. Will deliver update by the end of the week for both redux-object and json-api-normalizer.
PRs are also welcome 😃
closed via PR