Skip to content

Generalizations

Generalization is a special type of entity. In a generalization you have a base entity that holds common attributes and properties. The specialization entities holds specific information about its own entity. All entities within a generalization uses the same table to store their data. A discriminator column row_type is generated in the database code which will be used to identify between different derived (sub) entities.

It should be noted that each derived (sub) entity implements its own business logic (in model and source code files) including state machine and only uses the common table (of the base entity) to store and query data.

Model generalization entity using diagram

  1. Open or create a new overview diagram
  2. Check base entity included in the overview diagram. If currently not exists include it.
  3. Create new entity to be derived from the base entity. If it's already exists, include it to diagram.
  4. Create basedOn link from the derived entity to base entity. All inherited data will be included to the derived entity referring the base entity.
    If the derived entity already contains attributes, associations or states they will remain.
  5. Check that the derived entity's content is valid.
  6. Add additional attributes for the derived entity.
  7. Generate code for all entities. Database.cre, .api and.apy files will be generated.

Figure:  Sample of generalization in the overview diagram.

Model generalization entity using model file editor

  1. Create new base entity and add common attributes.
  2. In the source editor after the component name, type model command basedOn with its own entity name.
  3. Create new entity to be derived from the base entity.
  4. Open the base entity in the source editor and copy all it's attributes, references and states.
  5. Open derived entity in the source editor and paste them.
  6. In the source editor after the component name, type model command basedOn with the base entity name (i.e. this setting should occur both on the base and derived entities).
  7. Under the code gen properties, give the base entity's table name as DbTableName
  8. Add additional attributes for the derived entity.
  9. Generate code for all entities. Database.cre, .api and.apy files will be generated.

Considerations

  1. You should not insert records to the base entity (even if no hard error is raised if you do), only the derived entities are designed for inserts.
  2. Mandatory attributes may only exist in the base entity, but not in any derived entity (except for the derived attributes off course).