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: any entity (collection, table, ...) - or attribute herein - within a Hackolade can be an external definition for, and be referenced by, another Hackolade model.  In other words, it does not have to be a definition within that model.

Note: external model can be used to create a company-wide library of re-usable objects.  You may ask yourself whether it is best to have one single model hold all of your company's re-usable definitions, or to have one model per object, or various degrees in-between.  There are pros and cons to each approach.   We would advise against putting all objects in a single model.  One model per domain, or even one model per sub-domain would make more sense from these perspectives:

- maintenance responsibilities (maybe a department does not want its definitions be altered by another department)

- ease of navigation (directory names and model names should be descriptive so modelers don't have to scan tons of objects to find the ones that they're interested in)

- performance (not a huge factor, but smaller models are easier to navigate than bigger ones.)

Depending on size, you may even use sub-directories to help manage the library of definition models.  But do remember that, if you move referenced models around, you will break the path in the referencing 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.

External references are produced using the $ref implementation described here and RFC 3986.

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.

4) Where-Used

For internal and model definitions, it may be useful to find all occurrences of definition references within a model.  This where-used function (aka impact analysis, aka lineage) 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.)