- Entity models allow you to specify which data and behviors of entities are to be used for a specific use case.
- Models must always inherit from entities but may not declare any new fields.
- Models may hide data and behaviors from the inhering entities and they may declare new behaviors.
- Models or entities will be able to have templates. Templates will have a property specifying which if they may be applied to entities and / or models
- Only readonly models may hide non-nullable fields.
field auto id int aid;
field int bid;
field string Data;
field nullable int Type;
relative B with B on bid=bid as parent;
field auto id int bid;
field string Name;
model M1 : A as EntityBase
inherit field Type;
inherit relationship B;
validate Data customrule;
model readonly M2 : A as EntityBase
inherit field int Type;
inherit field B.Name;
Models have the following rules
- Models must inherit all id fields.
- Models must inherit all non-nullable fields.
- All non-id fields on Models marked with readonly are treated as if they were nullable.
- You may choose not to inherit nullable fields.
- You may choose not to inherit relationships.
- You may inherit fields from a relative.
- You may choose not to inherit rules.
The reasons for the above rules are there because if you try to insert a model you will need to have values for every single non-nullable field in order to do the inserts. If you want a very limited subset only for display purposes then you can create a readonly
model and since it doesn't need to be inserted or updated it will not need to inherit non-nullable fields.
Additionally relationships and rules are optionally inherited. You must specify to inherit them specifically. You may choose to inherit a field on a Model directly through a relationship, this will subsequently cause all data access code to directly join during
fetch operations. There will be no relationship object to load it will be as if it is a field directly apart of the model.
In the above example you would have the following results:
||does not inherit
||accessible through relationship