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.
Contents
- Open or create a new overview diagram
- Check base entity included in the overview diagram. If
currently not exists include it.
- Create new entity to be derived from the base entity. If it's
already exists, include it to diagram.
- 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.
- Check that the derived entity's content is valid.
- Add additional attributes for the derived entity.
- Generate code for all entities. Database .cre, .api and .apy
files will be generated.
Figure: Sample of generalization in the overview
diagram.
- Create new base entity and add common attributes.
- In the source editor after the component name, type model
command
basedOn
with its own entity name.
- Create new entity to be derived from the base entity.
- Open the base entity in the source editor and copy all it's
attributes, references and states.
- Open derived entity in the source editor and paste them.
- 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).
- Under the
code gen properties
give the base entity's table name as
DbTableName
- Add additional attributes for the derived entity.
- Generate code for all entities. Database .cre, .api and .apy files
will be generated.
Sample of base entity model in the model file editor
Sample of derived entity model in the model file editor
- 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.
- Mandatory attributes may only exist in the base entity, but
not in any derived entity (except for the derived attributes off course).