Skip to content

Commit

Permalink
[BUGFIX] #244 Fix removing belongsTo relations (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
frans-beech-it authored Oct 12, 2020
1 parent 228a35f commit ead645a
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ export class JsonApiDatastore {
data: relationshipData
};
}
} else if (data[key] === null) {
const entity = belongsToMetadata.find((entity: any) => entity.propertyName === key);

if (entity) {
relationships = relationships || {};

relationships[entity.relationship] = {
data: null
};
}
}
}
}
Expand Down Expand Up @@ -459,7 +469,7 @@ export class JsonApiDatastore {
const modelsTypes: any = Reflect.getMetadata('JsonApiDatastoreConfig', this.constructor).models;

for (const relationship in relationships) {
if (relationships.hasOwnProperty(relationship) && model.hasOwnProperty(relationship)) {
if (relationships.hasOwnProperty(relationship) && model.hasOwnProperty(relationship) && model[relationship]) {
const relationshipModel: JsonApiModel = model[relationship];
const hasMany: any[] = Reflect.getMetadata('HasMany', relationshipModel);
const propertyHasMany: any = find(hasMany, (property) => {
Expand Down

0 comments on commit ead645a

Please sign in to comment.