You can set the multiplicity and navigability of association roles as described in the introductory page. By default, association roles have multiplicity Any (
*), so all associations are initially created many-to-many.
Based on navigability, two types of associations can be distinguished:
Create a unidirectional association #
Right-click on the class you want to start the association from to open its
Class menu and select the
New relation >
Unidirectional association... option; a dotted line will appear running from the selected class to your cursor position. Move to another class and click on it.
Alternatively, click on the Palette icon
Create a new unidirectional association; click first on the source class and then on the target class, the class towards which the navigability direction points.
Let’s look at the following example (already covered in the introductory page): this is a unidirectional association, through which we can express an employee’s membership in a team. Since the relationship is navigable from the side of Team, we can access objects of this class from a GraphQL query referencing the Employee class. The multiplicity of the
team_ role is Zero or one (
01), therefore it is possible to associate at most one team to each employee, or none at all. On the other side of the association, multiplicity is Any (
*), so each team can be associated with any number of employees. However, since the
employee_ role is not navigable, it is not possible to see or associate any objects of class Employee by starting from the Team class.
Create a bidirectional association #
Right-click on one of the two classes you want to associate to open its
Class menu and select the
New relation >
Bidirectional association... option; a dotted line will appear running from the selected class to your cursor position. Move to another class and click on it.
Alternatively, click on the Palette
Create a new bidirectional association; click on one of the two classes you want to associate and then on the other one. In the case of bidirectional associations the order is not important.
The engine model of the next example allows us to associate employees (Employees) and projects (Projects); this operation can be done from both classes and without any restriction, because the association is bidirectional, with multiplicity many-to-many. An employee can thus participate in any number of projects, and any number of employees can work on a project.
Reflective associations #
An association (unidirectional or bidirectional) that associates objects that belong to the same class, instead of objects belonging to different classes, is called reflexive. In the Designer, this type of association is represented by a ring that falls within the source class; roles and direction of navigability behave as in any other association.
In a reflexive association, the names assigned to roles by default consist of the class name (with a lowercase initial) and the word
Source (for the outgoing role) or
Target (for the incoming role) separated by the
_ character. For example, in the association shown in the figure, the outgoing role would be called
employee_Source, while the incoming role would be called
Let’s look at the example: the association goes back inside the class Employee, creating a ring, so it allows to associate two objects of this class with each other. The meaning of the association is clarified by the name of the roles placed at the extremes of the relationship. In this case, one employee can designate another as his supervisor; the role of the association on the side where it falls into the Employee class has therefore been renamed from
supervisor, and the multiplicity has been set to Zero or one (
01). Since instead on the role side
employee_Source_ the multiplicity is Any (
*), each employee can be referred to as a supervisor by multiple people.
Although the relation falls within the source class, rather than reaching a new one, the ability to access objects in the application is still determined by the direction of navigability (as it is with any other relation). In this case, the association is unidirectional and points towards the
supervisor role: from an employee it is therefore possible to go back to his supervisor, but not vice versa.
Create a reflexive association #
Select the or the and double-click on the same class. A ring will automatically appear in the lower right corner with two roles on the same class.