Model object
This document describes the structure of the object that represents a data model when writing a template.
Before reading this document, you should take a look at the concepts section.
Within the templates
Injecting the data model
The template input can be defined as one model or all models.
During generation, if it is defined as one model, the template will be called once for each data model. Therefore, it will generate one file for each data model.
If it is defined as all models, the template will be called once for all data models. It will then generate a single file.
Single model
If the template requires only one model, then an object model ( alias m) will be available as a global variable in the template.
In a Hapify template, it will be available as Model, M or root.
In an EJS or JavaScript template, it will be available as model or m.
Multiple models
If the template requires all models, an array models ( alias m) will be available as a global variable in the template.
This array contains all available models.
In a Hapify template, it will be available as Models, M or root.
In an EJS or JavaScript template, it will be available as models or m.
Structure of the model object
The following objects will be available in the template.
Model object
id(string): an unique IDname(string): name of the model, as the user entered it.names(object): name variants computed from thenameproperty.raw(string): as the user entered it. ExampleOnline item.kebab(string): exampleonline-item.big(string): exampleONLINE-ITEM.header(string): exampleOnline-Item.snake(string): exampleonline_item.constant(string): exampleONLINE_ITEM.compact(string): exampleonlineitem.camel(string): exampleonlineItem.pascal(string): exampleOnlineItem.lower(string): exampleonline item.capital(string): exampleOnline Item.
notes(string): the notes of the model, as entered by the user.hasNotes(boolean): the model has notes.fields- aliasf(object): an object containing all fields, grouped in different arrays. See Field object section to learn more about field's structure.list- aliasl(array): containing all fields of the model.primary- aliaspr(Field): primary field of the model.nullif no primary field is defined.unique- aliasun(array): fields flagged asunique.label- aliaslb(array): fields flagged aslabel.nullable- aliasnu(array): fields flagged asnullable.multiple- aliasml(array): fields flagged asmultiple.embedded- aliasem(array): fields flagged asembedded.searchable- aliasse(array): fields flagged assearchable.sortable- aliasso(array): fields flagged assortable.hidden- aliashd(array): fields flagged ashidden.internal- aliasin(array): fields flagged asinternal.restricted- aliasrs(array): fields flagged asrestricted.ownership- aliasos(array): fields flagged asownership.searchableLabel- aliassl(array): fields flagged aslabelandsearchable. Useful for quick-search by label.filter- aliasf(Function): filter fields with a custom rule. Equivalent ofmodel.fields.list.filter.references- aliasr- non-deep model only (array): fields of typeentity.filter- aliasf(function): filter the array.
dependencies- aliasd- non-deep model only (object): dependencies (to other models) of this model. A model has a dependency if one of this field is of typeentity.list- aliasl(array): dependency models, but self. These models are added as "deep models".self- aliass(boolean): this model has a self-dependency.filter- aliasf(function): filter dependencies.- First argument (function - default
(f) => f): filter function receiving the referencer field (the entity field). - Second argument (boolean - default
true): boolean indicating if we should filter the self dependency.
- First argument (function - default
referencedIn- aliasri- non-deep model only (array): models that refer to this one. These models are added as "deep models". These models only contains fields of typeentityreferring to the current model.filter- aliasf(function): filter the array.
properties- aliasp(object): pre-computed properties from fields.fieldsCount(number): the number of fields contained in the model.hasPrimary(boolean): model has a primary field.hasUnique(boolean): model has at least one unique field.hasLabel(boolean): model has at least one label field.hasNullable(boolean): model has at least one nullable field.hasMultiple(boolean): model has at least one multiple field.hasEmbedded(boolean): model has at least one embedded field.hasSearchable(boolean): model has at least one searchable field.hasSortable(boolean): model has at least one sortable field.hasHidden(boolean): model has at least one hidden field.hasInternal(boolean): model has at least one internal field.hasRestricted(boolean): model has at least one restricted field.hasOwnership(boolean): model has at least one ownership field.hasSearchableLabel(boolean): model has at least one field marked as label and also searchable.hasDependencies- non-deep model only (boolean): model has dependencies to other models or itself (through anentityfield).isReferenced- non-deep model only (boolean): model is referenced by other models.mainlyHidden(boolean): most of the fields are hidden (strictly).mainlyInternal(boolean): most of the fields are internal (strictly).isGeolocated(boolean): model contains at least one latitude field and one longitude field.isGeoSearchable(boolean): model contains at least one searchable latitude field and one searchable longitude field.
accesses- aliasa(object): action's accesses grouped by action or restriction. See Access object section to learn more about access' structure.list- aliasl(array): action's accesses of the model.admin- aliasad(array): action's accesses restricted toadmin.owner- aliasow(array): action's accesses restricted toowner.auth- aliasau(array): action's accesses restricted toauthenticated.guest- aliasgs(array): action's accesses restricted toguest.create- aliasc(object): thecreateaction's access.read- aliasr(object): thereadaction's access.update- aliasu(object): theupdateaction's access.remove- aliasd(object): thedeleteaction's access.search- aliass(object): thesearchaction's access.count- aliasn(object): thecountaction's access.filter- aliasf(Function): filter action's accesses with a custom rule. Equivalent ofmodel.accesses.list.filter.properties- aliasp(object): pre-computed properties from action's accesses.onlyAdmin(boolean): model only contains actions restricted toadmin.onlyOwner(boolean): model only contains actions restricted toowner.onlyAuth(boolean): model only contains actions restricted toauthenticated.onlyGuest(boolean): model only contains actions restricted toguest.maxAdmin(boolean): most permissive access isadmin.maxOwner(boolean): most permissive access isowner.maxAuth(boolean): most permissive access isauthenticated.maxGuest(boolean): most permissive access isguest.noAdmin(boolean): there is no action restricted toadmin.noOwner(boolean): there is no action restricted toowner.noAuth(boolean): there is no action restricted toauthenticated.noGuest(boolean): there is no action restricted toguest.hasAdmin(boolean): there is at least one action restricted toadmin.hasOwner(boolean): there is at least one action restricted toowner.hasAuth(boolean): there is at least one action restricted toauthenticated.hasGuest(boolean): there is at least one action restricted toguest.
Field object
name(string): name of the field, as the user entered it.names(object): name variants computed thenameproperty. As for the model object.raw(string): as the user entered it. Examplefirst_name.kebab(string): examplefirst-name.big(string): exampleFIRST-NAME.header(string): exampleFirst-Name.snake(string): examplefirst_name.constant(string): exampleFIRST_NAME.compact(string): examplefirstname.camel(string): examplefirstName.pascal(string): exampleFirstName.lower(string): examplefirst name.upper(string): exampleFIRST NAME.capital(string): exampleFirst Name.
notes(string): the notes of the field, as entered by the user.hasNotes(boolean): the field has notes.primary(boolean): field is flagged asprimary.unique(boolean): field is flagged asunique.label(boolean): field is flagged aslabel.nullable(boolean): field is flagged asnullable.multiple(boolean): field is flagged asmultiple.embedded(boolean): field is flagged asembedded.searchable(boolean): field is flagged assearchable.sortable(boolean): field is flagged assortable.hidden(boolean): field is flagged ashidden.internal(boolean): field is flagged asinternal.restricted(boolean): field is flagged asrestricted.ownership(boolean): field is flagged asownership.type(string): type of the field. Can bestring,number,boolean,datetime,entity,objectorfile.subtype(string): subtype of the field. The available values depend on thetype:string: Can benull,email,password,url,textorrich.number: Can benull,integer,float,latitudeorlongitude.boolean: Isnull.datetime: Can benull,dateortime.entity: Isnull.object: Isnull.file: Can benull,image,video,audioordocument.
model- aliasm(object): target model object if the field is of typeentity.nullotherwise.enum- aliase(array): an array containing all enum if the field is of typeenum.nullotherwise. See Enum object section to learn more about enum's structure.value(string|string[]):- If type is
entity: raw ID of the target model (string). - If type is
enum: raw enum list (string[]). - Otherwise
null.
- If type is
Enum object
name(string): name of the enum, as the user entered it.names(object): name variants computed thenameproperty. As for the field and model object.raw(string): as the user entered it. Examplefirst_name.kebab(string): examplefirst-name.big(string): exampleFIRST-NAME.header(string): exampleFirst-Name.snake(string): examplefirst_name.constant(string): exampleFIRST_NAME.compact(string): examplefirstname.camel(string): examplefirstName.pascal(string): exampleFirstName.lower(string): examplefirst name.upper(string): exampleFIRST NAME.capital(string): exampleFirst Name.
Access object
action(string): name of the action. Can becreate,read,update,remove,searchorcount.admin(boolean): access isadmin.owner(boolean): access isowner.auth(boolean): access isauthenticated.guest(boolean): access isguest.gteAdmin(boolean): access is greater or equal thanadmin(should always betrue).gteOwner(boolean): access is greater or equal thanowner.gteAuth(boolean): access is greater or equal thanauthenticated.gteGuest(boolean): access is greater or equal thanguest.lteAdmin(boolean): access is less or equal thanadmin.lteOwner(boolean): access is less or equal thanowner.lteAuth(boolean): access is less or equal thanauthenticated.lteGuest(boolean): access is less or equal thanguest(should always betrue).