-
Notifications
You must be signed in to change notification settings - Fork 199
Open
Description
If there are relationships that share resources, and are included only once each (see the example below - there are only two books but one is both a "selling" and a "favorite") when they are deserialized the second instance of the repeated relationship is not properly included (it just places null)
{
"data": {
"type": "user",
"id": "5ad2601522c6f6733408ae1f",
"attributes": {...},
"relationships": {
"favorite": {
"data": [
{
"type": "book",
"id": "5aca58621d13177065279691"
}
]
},
"selling": {
"data": [
{
"type": "book",
"id": "5ac8dd784f904b5a281aa061"
},
{
"type": "book",
"id": "5aca58621d13177065279691"
}
]
}
}
},
"included": [
{
"type": "book",
"id": "5aca58621d13177065279691",
"attributes": {...},
},
{
"type": "book",
"id": "5ac8dd784f904b5a281aa061",
"attributes": {...}
}
]
}
When deserialized, this returns
{
...
"id": "5ad2601522c6f6733408ae1f",
"selling": [
{
...
"id": "5ac8dd784f904b5a281aa061"
},
null <-- Relationship was included but presumably used up for something else!
],
"favorite": [
{
...
"id": "5aca58621d13177065279691"
}
]
}
shupac, sreecodeslayer, avdeev, ajmathews and copet80copet80
Metadata
Metadata
Assignees
Labels
No labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
AELSchauer commentedon May 3, 2018
This is a known issue with this repo but the author hasn't done anything to publicly address it. I forked this repo to fix this issue. You can view the PR here:
#170
And you can view my fork here:
https://github.com/AELSchauer/jsonapi-serializer
shupac commentedon Oct 17, 2018
just ran into this issue. @AELSchauer I checked out your branch but it wasn't working for me
SeyZ commentedon Oct 28, 2018
I'm currently trying to reproduce this issue on my side and everything looks fine:
OUTPUT:
Any help to reproduce ?
vovkvlad commentedon Jun 5, 2019
I have a pretty similar issue, but without null - it just does not include nested relationship for the second time - it's just omitted. It looks that as if it has already used it for the first time, and in the second time - it's not there. Reroducible code is here:
https://codesandbox.io/s/jsonapiserializer-bug-wez5c?fontsize=14
konovalov-nk commentedon Aug 8, 2019
Can confirm. Just spent ~6 hours figuring this out + 2 hours on adapting solution by @AELSchauer (thanks a lot!). Glad this issue was already pointed out or I'd have to spend even more time thinking I've gone mad 😄
Basically, having circular dependencies on your resources is not possible due to references evaluated as
null
.A simple example would be the following JSONAPI response:
4e70016 without a patch produces following result:
Demonstration available here.
Update deserializer-utils.js
Update deserializer-utils.js