Relationships


Relationships can be added from the Entity Options panel (you can open this panel by clicking on the Entity).


Schema

{info} Vemto will automatically generate the Foreign Keys, Pivot Tables, and the Inverse Relationship for created relationships. It is not necessary to create this kind of stuff manually (but you can do it if you want).

Creating

To add a new relationship, you can click on the Add Relationship button under the Entity Options. Then, just select the relationship type and the related model to show the type-specific relationship options.


image

Belongs To

A Belongs To relationship has the following options:

  • Relationship Name - By default, is the related model name in lower case
  • Foreign Key Name - Vemto will suggest the foreign key name following the Laravel standard (but you can change it if you want). If a field with this name exists in the local model, Vemto will use it. Otherwise, the field/foreign will be automatically added to the local model.


image

{info} After saving a "Belongs To" relationship, an inverse "Has Many" relationship will be automatically added to the related model.

Has Many and Has One

A Has Many or Has One relationship has the following options:

  • Relationship Name - By default, is the related collection name in lower case
  • Foreign Key Name - Vemto will suggest the foreign key name following the Laravel standard (but you can change it if you want). If a field with this name exists in the related model, Vemto will use it. Otherwise, the field/foreign will be automatically added to the related model.


image

{info} After saving a "Has Many" or "Has One" relationship, an inverse "Belongs To" relationship will be automatically added to the related model.

Belongs To Many

A Belongs To Many relationship has the following options:

  • Relationship Name - By default, is the related collection name in lower case
  • Pivot Table Name - Follows the default Laravel Convention for pivot tables. If you decide to don't follow the standard convention, Vemto automatically sets the correct configuration inside the Model relationships (but it is always recommended to use the standard names). The pivot table will be created if it is not existing in the current schema
  • Local Model Key Name - The FK name for the local model on the pivot table
  • Joined Model Key Name - The FK name for the joined model on the pivot table

{warning} Vemto will automatically suggest foreign names based on Laravel standards. If you are using a custom pivot table that doesn't follow the standards, it will be necessary to change the foreign names when creating the relationship


image

{info} After saving a Belongs To Many relationship, an inverse Belongs To Many relationship will be automatically added to the related model, and a Pivot Table, if necessary.

Pivot Table

By default, Vemto automatically generates Pivot Tables when adding a Belongs To Many relationship. So, it is highly recommended to let Vemto take care of it.


But, if you want to add these pivot tables manually, please be sure to follow the Laravel Many to Many Relationships conventions to make sure these tables work well with the Eloquent ORM.


Pivot Table