Types of relations for connecting models

Describes the different types of relations that are available for defining the connections between models

Updated over a week ago

Relations represent the connection between the models. The relation type determines the connection between individual models. Models can have one or more different types of connections. The following list of the different relation types describes the connection and provides an example of when it can be used:

Belongs to (many sources belong to one target)

Multiple objects as defined in the source model are related to a single object as defined by the target model.

The source model (reservation) obtains a new object property that will store an object of the target model (reservation.room), the target model (room) obtains a new collection property that stores multiple objects of the source model (room.reservations).

Many tasks are assigned to one Team.

Many players belong to one team.

Many order lines make up one order.

Many reservations belong to one room.

Has many (single source has many targets)

This means that one object of the source model is related to multiple objects of the target model.

The source model (room) obtains a new collection property that stores multiple objects of the target model (room.reservations). The target model (reservation) obtains a new object property that stores an object of the source model (reservation.room).

A project has many tasks.

A movie has many actors playing in it.

A pizza is made out of many ingredients.

One room has many reservations.

Has and belongs to many (One source has and belongs to many targets)

This is a many to many relation. Multiple objects of the source model are related to multiple objects of the target model.

The source model (user) obtains a new collection property that stores multiple objects of the target model (user.roles). The target model (role) obtains a new collection property that stores multiple objects of the source model (role.users).

A student takes many classes.

A movie involves many actors playing in it.

An author can write multiple books but a book can also be written by many authors.

A user can have multiple roles and those roles can also be applied to multiple other users.

Self-Referencing Relationships

These types of relationships involve only a single model.

Team roles in organizations - for example, an Employee model that represents the employees in an organization. Various employees can be assigned as supervisors or team leaders for multiple employees.

An employee is an employee of an organization and simultaneously the supervisor of multiple employees.

Did this answer your question?