modelsdk how to retrieve persistent entities only

2
In ModelReflection, it is possible to get all entities and filter e.g. the persistable-ones. In the ModelSDK, I can get the entities by domainmodel.entities. However, there does not seem to be a property that states whether an entity is persistent or not. How can I find only the persistent entities in my model, e.g. for code analysis?
asked
2 answers
1

Hi Marien,

You are close, the entity.generalization property indeed refers to the GeneralizationBase, which is abstract (like all Base postfixed classes). But it has two suptypes: Generalization and NoGeneralization (see the docs)

If the entity has no supertype its generalization property will be an instanceof NoGeneralization, which has a property persistable which is the one you are looking for.

if the entity has a supertype (inherits from another entity), the generalization will be an instanceof Generalization, which has itself also property generalization which refers to the entity it is inheriting from. Which might in turn inherit from another, but in the end there will be always an entity with NoGeneralization; that is the one that determines the persist-ability for the whole inheritance chain.

In other words, a simple recursive function can tell you whether an entity is persistable:

function isPersistable(entity: domainmodels.IEntity): boolean {
    if (!entity || !entity.generalization)
        return true; // Default if somehow no info available, this happens when inheriting from entities in the System module which is currently not available in the sdk
    else if (entity.generalization instanceof domainmodels.NoGeneralization)
        return (<domainmodels.INoGeneralization>entity.generalization).persistable;
    else
        return isPersistable((<domainmodels.IGeneralization>entity.generalization).generalization);
}

Note that this is a pattern used quite often used in the SDK, some property refers to an abstract object, which, depending on the concrete subtype, reveals more properties

answered
1

It is Entity.GeneralizationBase.Persistable.

answered