Skip to content

Commit

Permalink
getRelationshipURL does not return local identifier anymore (#144)
Browse files Browse the repository at this point in the history
* getRelationshipURL does not return local identifier anymore

* Remove updating model links when assigning a has many relationship
  • Loading branch information
safo6m authored Apr 28, 2023
1 parent bc96e9e commit ba59045
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 9 additions & 4 deletions projects/ngx-hal/src/lib/models/hal.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export abstract class HalModel<Datastore extends DatastoreService = DatastoreSer
this.parseAttributes(resource);
this.parseHeaderAttributes(rawResponse);
this.initializeHasOneProperties();
this.initialzieHasManyProperties();
this.initializeHasManyProperties();
this.extractEmbeddedProperties(resource);
}

Expand Down Expand Up @@ -117,7 +117,13 @@ export abstract class HalModel<Datastore extends DatastoreService = DatastoreSer
}

const fieldName: string = property.externalName || relationshipName;
return this.links[fieldName] ? this.links[fieldName].href : '';
const url = this.links[fieldName] ? this.links[fieldName].href : '';

if (!url || url.startsWith(LOCAL_MODEL_ID_PREFIX) || url.startsWith(LOCAL_DOCUMENT_ID_PREFIX)) {
return null;
}

return url;
}

public getPropertyData(propertyName: string): ModelProperty {
Expand Down Expand Up @@ -425,7 +431,7 @@ export abstract class HalModel<Datastore extends DatastoreService = DatastoreSer
});
}

private initialzieHasManyProperties(): void {
private initializeHasManyProperties(): void {
this.hasManyProperties.forEach((property: ModelProperty) => {
Object.defineProperty(this, property.name, {
configurable: true,
Expand Down Expand Up @@ -453,7 +459,6 @@ export abstract class HalModel<Datastore extends DatastoreService = DatastoreSer
halDocumentRaw.uniqueModelIdentificator,
);
this.datastore.storage.save(halDocumentRaw);
this.replaceRelationshipModel(property.externalName, halDocumentRaw);
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ export class DatastoreService {
);
}

if (
!url ||
url.startsWith(LOCAL_MODEL_ID_PREFIX) ||
url.startsWith(LOCAL_DOCUMENT_ID_PREFIX)
) {
if (!url) {
continue;
}

Expand Down

0 comments on commit ba59045

Please sign in to comment.