Model Relations

Define the relations between the current model and other models.

By clicking on the Add Relation button you can start generating a new relation.

After selecting one of the existing relations, its details will be shown and you will be able to edit it.

Relation Details

To define a new relation, first select the relation type.

Optionally you can decide if the relation should be added to the model's Api resource, what name you want to assign to it (by default it is the name of the target model's table) and when it should be added : only if the relation is loaded on the model (When Loaded) or Always.

Next, you need to specify which target model should be put in relation with the selected one.

After selecting the target model, Hatthi will complete the rest of the relation for you, by automatically selecting the eligible fields (foreign and primary keys) for the relation and defining the inverse relation, as the constraints of the current relation.

If there is only one eligible field, you will have no option to edit it; otherwise you will be able to select which field to use for the relation.

Finally, you can chose the name of the relation and if it's going to be eager loaded or not.

You can also define the behavior of the used field when the related one is updated (ON UPDATE) and deleted (ON DELETE).

The last row describes the inverse relation, which is editable only in the Many to Many relations and works the same way as defiining the main relation. The name of the inverse relation is always editable.

To save the newly added/modified relation, click on the save button ().