9.6.1 Relationship types
A relationship consists of a relation and a direction. The possible relations are OneToOne, ManyToOne, OneToMany, and ManyToMany. Furthermore, the possible directions of each relation are unidirectional and bi-directional. The relations and directions are combined to form the following seven types of relationship:
-
Unidirectional OneToOne relationship
-
Unidirectional ManyToOne relationship
-
Unidirectional OneToMany relationship
-
Unidirectional ManyToMany relationship
-
Bi-directional OneToOne relationship
-
Bi-directional ManyToOne/OneToMany relationship
-
Bi-directional ManyToMany relationship
This section describes relationships using the employees and departments of a company as an example. The relation between the employees and departments is as follows:
-
The entity expresses the employees and departments respectively.
-
The employees are assumed to belong to some department.
-
A department maintains multiple employees.
-
The departments are referenced from employees and the employees are referenced from departments.
This example expresses the bi-directional ManyToOne/ OneToMany relationship of entities. In this case, Many stands for the employees and One stands for the department. The following figure shows the relation between the employee entity and the department entity.
Note that in an entity, you can specify settings to propagate the operations to the relation destination entity. These settings are called cascade. When you perform an operation for an entity and if cascade is specified, similar operations are automatically executed even in the entities that have a relationship with the operated entity. If cascade is used, the user can save the effort of performing operations for the relation destination entity.