Relationships that Contains an Empty Data Array Should Deserialise
BlairAllegroTech opened this issue · comments
Taken comments against, #1 report by @rgant
I've found an issue with this test:
js-data-jsonapi/src/JsonApiSerializer.ts
Line 936 in d67ff61
if (relationship.data) {
In JavaScript an empty array is true.
> Boolean([]);
true
I think you need to make the test be:
if (relationship.data.length) {
Something in the code makes all relationships have an empty data array. Maybe this code?
function JsonApiRelationship() {
this.links = {};
this.data = new Array();
}
This code after the test causes an issue for me:
var childRelationType = DSUTILS.isArray(relationship.data) ? relationship.data[0].type : (<JsonApi.JsonApiData>(<any>relationship.data)).type;
Because if relationship.data
is []
then relationship.data[0].type
raises an error.