What are the three relation types?


After reading this article you will know:

  • Which different relation types there are
  • 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


The three relation types are: belongs to, has many and has and belongs to many. We will deep into some examples:

  • Belongs to: defines that more than one object of the source model can relate to one object of the target model (more lines belong to one Order).
  • Has many: indicates that one object of the source model can relate to more than one object of the target model (one Client can have multiple Orders).
  • Has many and Belongs to many: defines that more than one object of the source model can relate to more than one object of the target model (one Employee can work for one or multiple Departments).

Sample

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.

Didn’t find what you want?Ask your question on the forum!