I'm using Angular 5 + Breeze JS + breeze-bridge2-angular.
Suppose we have a Company entity that have multiple navigation properties of type Address and Address entity type, in its own turn, has some navigation properties like Country, etc:
import { Entity } from "breeze-client"; // From https://www.npmjs.com/package/breeze-client package
export class Company implements Entity {
billingAddress: Address;
shippingAddress: Address;
}
export class Address implements Entity {
country1: Country;
country2: Country;
}
export class Country implements Entity {
...
}
All entities have been already queried into EntityMnager, no need to query anything from server.
How to implement a method (probably using some Breeze JS API I'm missing so far) taking a parent Company entity and a string[] of dotted property paths and returns a flat Entity[] list containing parent entity and all child entities located by using those dotted paths?
The dotted paths are just the same as we use with expand() method in Breeze queries (see Dotted expand paths here), i.e.:
const company: Company = ...; // Query Company and its children into EntityManager
const paths: string[] = [
"billingAddress",
"shippingAddress",
"billingAddress.country1",
"billingAddress.country2"];
getEntitiesFlat(entity: Entity, paths: string[]): Entity[] {
// Not sure how to implement getChildren() method below
const childEntities: Entity[] = this.getChildren(entity, paths);
return [entity].concat(childEntities);
}
By the way, I'm trying to implement deletion of parent entity and its specific child entities and the above is the cleanest way I've came up so far inspired by DevForce framework. Better ideas are extremely welcomed.
not really sure what you're looking for. Assuming you're taking
pathand mapping those paths against theentityobject... I came up with:use like
edit: if you're using
lodashalready, just uselodash#get