-
Notifications
You must be signed in to change notification settings - Fork 197
Description
I found one very strange bug working with this library. What happens is that in some cases nested relationships (which are included as well in "included" list) do get serialized and sometimes they don't. I actually took the example from your tests (this one), pasted it beside my non-working example, adapted both to look exactly the same, and tried to figure out what went wrong.
Conclusion is very strange. Apparently when "data" type has "relationship" type on it's beginning, that relationship won't resolve it's relationships even though they are included. It sound's strange, but here is an adapted example taken from earlier mentioned tests.
const testData = {
data: {
type: "user",
id: "54735750e16638ba1eee59cb",
attributes: {
"first-name": "Sandro",
"last-name": "Munda"
},
relationships: {
address: {
data: { type: "address", id: "54735722e16620ba1eee36af" }
}
}
},
included: [
{
type: "address",
id: "54735722e16620ba1eee36af",
attributes: {
"address-line1": "406 Madison Court",
"zip-code": "49426",
country: "USA"
},
relationships: {
lock: {
data: { type: "lock", id: "1" }
}
}
},
{
type: "lock",
id: "1",
attributes: {
"secret-key": "S*7v0oMf7YxCtFyA$ffy"
}
}
]
};
new Deserializer({
keyForAttribute: "camelCase",
pluralizeType: false
})
.deserialize(testData)
.then(res => console.log(res));In given example, console would look as expected, it would have user attributes, and address attribute containing all of the "address" relationship attributes and lock attribute, containing all of the "lock" relationship attributes.
{
firstName: "Sandro",
lastName: "Munda",
id: "54735750e16638ba1eee59cb",
address: {
addressLine1: "406 Madison Court",
zipCode: "49426",
country: "USA",
id: "54735722e16620ba1eee36af",
lock: {
secretKey: "S*7v0oMf7YxCtFyA$ffy",
id: "1"
}
}
}But, if you change top level data type from "users" to "addressUsers" (or anything that starts with "address") it would just skip "lock" part, and the result would look like this:
{
firstName: "Sandro",
lastName: "Munda",
id: "54735750e16638ba1eee59cb",
address: {
addressLine1: "406 Madison Court",
zipCode: "49426",
country: "USA",
id: "54735722e16620ba1eee36af",
}
}I'm not sure how is that possible, or what is going on in the background, but this is a real problem for me, and it'd be great if someone could check it out and even provide a solution for it.
Thanks in advance!