After reading this article you will know:

  • What the different relation types are
  • How the different relation types are used
  • Some sample uses of the three types of relations

In the What's a relational model article, you have learned that the type of relation between models indicates the number of related objects. In this article, we explain the three types of relations and the number of related objects they indicate.

The three relation types explained

Relations are a big part of a relational datamodel. Within Betty Blocks there are 3 different types of relations that can be used to link models to each other. The different relation types are:

  • Belongs to: This is a many to one relation. This means that multiple objects of the source model can be related to one object of the target model. The source model will get a new object property that will store an object of the target model, the target model will get a new collection property that will store multiple objects of the source model.
  • Has many: This is a one to many relation. This means that one object of the source model can be related to multiple objects of the target model. The source model will get a new collection property that will store multiple objects of the target model, the target model will get a new object property that will store an object of the source model.
  • Has many and Belongs to many: This is a many to many relation. This means that multiple objects of the source model can be related to multiple objects of the target model. The source model will get a new collection property that will store multiple objects of the target model and the target model will get a new collection property that will store multiple objects of the source model.

Examples

Belongs to

  • An Invoice belongs to one Customer.
  • A Sales lead belongs to one Account.
  • An Invoice belongs to one Order.
  • An Order line belongs to one Order.
  • An Order line belongs to one Product.

Has many

  • One Customer has many Invoices.
  • One Customer has many Addresses.
  • One Account has many Sales leads.
  • One Course has many Scheduled times.
  • One Contact has many Contact moments.

Has and belongs to many

  • A Sales employee has and belongs to many Sourced leads.
  • A User has and belongs to many Roles.
  • A Branche has and belongs to many Branche groups.
  • An Employee has and belongs to many Projects.
  • An Assembly has and belongs to many Parts.
  • A Course has and belongs to many Trainees.
Did this answer your question?