Re-usable objects definitions
Note: You may wish to view the how-to video on this subject.
To facilitate the work of data modelers, Hackolade has introduced a handy feature: the ability to create once object definitions that can be re-used in multiple places. A library of definitions standardizes content and insures consistency. This dictionary also simplifies the work of data modelers so maintenance can be performed in one place and be automatically propagated to all places where the definition is referenced.
A good simple example of a re-usable definition is an address. This type of object may be used in many places inside a model, and in different models too. Even within one single entity, you may have, for example a billing address and a shipping address.
Definitions can be maintained at 3 distinct levels: at the entity-level (called internal definitions), at the model-level, and external. Internal definitions have limited use because they can only be reused (or referenced) within the same entity (a collection or table). But internal definitions insure JSON Schema compatibility. Model definitions can be referenced in any entity of the same Hackolade model. Finally, external definitions are Hackolade models (or JSON Schema files) that can be referenced in whole or in part, by other models.
Note: In order for changes to a referenced external model to be activated in a referencing model, the latter needs to be opened in the application.
If a definition is created at the model level, it can be referenced in any entity of the same model, whereas it will be limited to its own entity if it is created internally. It is easy to create a re-usable definition from scratch, then reference it in a collection. Or by selecting an attribute in an existing collection, and converting it to a re-usable definition, so it can be referenced elsewhere.
Note: Definitions are not carried over to the NoSQL database. They are only used in physical modeling in Hackolade. To make things easy for the data modeler, Object Browser, ERD, collection tree views, and documentation all show the referenced attributes as if they had been defined directly in the collection(s).
When displaying the JSON Schema preview or forward-engineering JSON Schema, the user may choose between the standard 'Referenced definitions'
or 'Resolved definitions'
A good example of a useful re-usable object is an address. You may want to have a 'billing address' and a 'shipping address', both of which use the same structure.
1) Reference to another Hackolade model or a JSON Schema file
If you have defined a separate model with the structure of an address, you may reference it in any other Hackolade model:
next, you're prompted to choose the reference model, either from your file system or a URL:
You then can choose an individual attribute, or an entire structure:
Note: it is not intended to combine definition levels. In other words, if you have a Hackolade model with attribute structures intended to be re-used in other models, you should define these as simple attributes, not as internal or model definitions.
2) Initially create a definition
A definition can be created from scratch, just like any collection, either by selecting the Model Definitions lower tab at the model ERD level:
or by selecting the Internal Definitions lower tab at the collection level:
In our address example, the definition may look like this:
Once the definition is created, it can be referenced in a collection, via the contextual menu:
As a result, a reference is created in the collection. The application displays all the elements of the definition, as if they were in the collection, but only a reference to the definition is actually stored in the collection:
The reference is marked with the middle line in the tree box, showing the name of the referenced definition, followed by either (m) for model definitions, or (i) for internal definitions.
At any point, it is possible, if desired, to replace a reference by the object definition structure:
3) Convert an existing attribute into a definition
If you want to make an attribute available for use elsewhere in the same collection, or in another collection, you can convert it with just a few clicks:
This will create the internal or model definition, and replace the attribute (and its children if any) by a reference to the definition.
For internal and model definitions, it may be useful to find all occurrences of definition references within a model. This lineage function (aka impact analysis, aka where-used) is available from the contextual menu (or the Ctrl+F11 shortcut key):
Choosing this option displays a dialog displaying all instances of references to the selected definition, and the path to those instances.
You may select an instance and go to the tree view of that reference. Lineage is enabled from the Object Browser and definition tab (model and internal.)