Skip to content

Commit ead645a

Browse files
[BUGFIX] #244 Fix removing belongsTo relations (#245)
1 parent 228a35f commit ead645a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

projects/angular2-jsonapi/src/services/json-api-datastore.service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ export class JsonApiDatastore {
287287
data: relationshipData
288288
};
289289
}
290+
} else if (data[key] === null) {
291+
const entity = belongsToMetadata.find((entity: any) => entity.propertyName === key);
292+
293+
if (entity) {
294+
relationships = relationships || {};
295+
296+
relationships[entity.relationship] = {
297+
data: null
298+
};
299+
}
290300
}
291301
}
292302
}
@@ -459,7 +469,7 @@ export class JsonApiDatastore {
459469
const modelsTypes: any = Reflect.getMetadata('JsonApiDatastoreConfig', this.constructor).models;
460470

461471
for (const relationship in relationships) {
462-
if (relationships.hasOwnProperty(relationship) && model.hasOwnProperty(relationship)) {
472+
if (relationships.hasOwnProperty(relationship) && model.hasOwnProperty(relationship) && model[relationship]) {
463473
const relationshipModel: JsonApiModel = model[relationship];
464474
const hasMany: any[] = Reflect.getMetadata('HasMany', relationshipModel);
465475
const propertyHasMany: any = find(hasMany, (property) => {

0 commit comments

Comments
 (0)