Skip to content

Commit

Permalink
Add existance check on belongs to parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidoz committed Sep 22, 2016
1 parent 3871511 commit 3f538a0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/models/json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ export class JsonApiModel {
let relationship: any = data.relationships[metadata.relationship];
if (relationship && relationship.data) {
let dataRelationship: any = (relationship.data instanceof Array) ? relationship.data[0] : relationship.data;
let typeName: string = dataRelationship.type;
let modelType: ModelType = Reflect.getMetadata('JsonApiDatastoreConfig', this._datastore.constructor).models[typeName];
let relationshipModel: JsonApiModel = this.getBelongsToRelationship(modelType, dataRelationship, included, typeName, level);
if (relationshipModel) {
this[metadata.propertyName] = relationshipModel;
if (dataRelationship) {
let typeName: string = dataRelationship.type;
let modelType: ModelType = Reflect.getMetadata('JsonApiDatastoreConfig', this._datastore.constructor).models[typeName];
let relationshipModel: JsonApiModel = this.getBelongsToRelationship(modelType, dataRelationship, included, typeName, level);
if (relationshipModel) {
this[metadata.propertyName] = relationshipModel;
}
}
}
}
Expand Down

0 comments on commit 3f538a0

Please sign in to comment.