4.1.3 Relationships and Roles
Selecting relationships and roles
To select a relationship or role, you must click with the
mouse in or near one of its selection areas. For relationships, the selection
area is at the meeting point of the role lines, and is either the graphical
symbol or label text for the relationship, or a red dot if there is no symbol.
For roles, the selection area is the role line and possible symbol at the end of
it. When a relationship is selected it displays selection handles around its
symbol, or a single selection handle if it has no symbol. When a role is
selected it displays a selection handle at both ends of its line, and also for
any breakpoints along the line.
To select multiple relationships or roles, select the
first element by clicking it with the left mouse button, then holding
Ctrl down while you click each of the other elements. Alternatively, you
can select all design elements in an area by clicking and dragging with the left
mouse button to define the area you want to select.
To select all elements in the drawing area (i.e. all
objects, relationships and roles), select
Edit | Select All or use the
shortcut key
Ctrl+A.
Editing relationship properties
Relationships are connections between objects. In the Diagram
Editor these are represented as the meeting point of role lines, possibly with
an associated symbol. Relationships can be viewed and
edited similarly to objects. To edit the properties of a
relationship:
1) | Select
the
relationship. |
2) | Open
the relationship’s pop-up menu (with the right mouse button) and select
Properties... Alternatively you may use a keyboard shortcut by pressing
Enter, or select Edit |
Properties.... |
| As
a result a property dialog appears allowing you to edit the information about
the
relationship. |
 | By
default, the right mouse button first selects an element then opens the pop-up
menu for it. This can be changed to just open the pop-up menu. See Section 3.1.3 Options
Tool. |
Adding binary relationships
To add a new binary relationship (i.e. a relationship between
two objects):
1) | Select
the relationship type from the toolbar or the Types
menu. |
2) | Move
the cursor over the first object so that it becomes highlighted as in Figure
4–12. |
| The
highlighted part of the symbol is called its connectable. Usually there is only
one connectable per symbol. It is also possible to have multiple connectables,
each of them being a representation of a port (for more information about ports,
see Section 6.2.3). Hovering over a
port will show its name and type in the Status bar. If you try to connect a
relationship to an illegal port, a warning dialog will show
up. |

Figure 4–12.Creating binary relationship.
3) | Press
and hold down the left mouse button, drag the cursor over the other object so
its connectable becomes highlighted, and release the mouse
button. |
As a result a dialog window opens
with possible relationships to be added. Each item is a binding, consisting of a
relationship, the roles that will be created with the relationship, and which
object will be in which role. Selecting an item will show a preview of the
selected binding in the drawing area. Depending on your preference settings for
relationship creation (Section
3.1.3),
the order in which you select objects may affect the choices and assignment of
roles to objects. If only one combination of relationships and roles is possible
the tool bypasses this dialog and the property dialog appears immediately. This
dialog contains tabs for property dialogs on the relationship and each of the
roles.
 | If
a relationship or a role does not have properties, the tab label text on the
notebook page is italicized. The tab label for roles also shows the name of the
object to which that role attaches.
|
4) | Fill
in the properties of the new relationship and roles. Click the tab labels to
move between relationship and role
pages. |
5) | Accept
the new relationship and its roles by clicking All OK.
|
Alternatively, you can also create a
binary relationship as in previous versions of MetaEdit+. Selecting the first
object, and choose
Connect... from its pop-up menu. As you move the
cursor to another object, a line will follow it from the first object. Press the
left mouse button over the second object, and fill in the property dialogs as
above.
Adding an n-ary relationship
To create an n-ary relationship (i.e. a relationship involving
more than two objects):
1) | Select
the type for the new relationship from the toolbar or the Types menu, and
click the first object (as in Figure
4–13). |
2) | Click
in the spot where you want to place the relationship. A red dot will appear
there as a placeholder for the
relationship. |
3) | Add
each role by clicking each required
object. |

Figure 4–13.Creating an n-ary relationship.
4) | Once
you have added all roles, finalize the relationship creation by pressing the
right mouse button. You can avoid this step and finalize the relationship
creation while creating the last role by double-clicking the last
object. |
5) | Answer
the property dialogs if necessary. |
It is
also possible to skip step 1, by placing the relationship first. The role to the
first object should then be drawn as the first role in step 3.
N-ary relationships can also be created as in previous
versions of MetaEdit+: first select all the objects that you want in the
relationship (e.g. by Ctrl-clicking them) and then select
Connect... from the pop-up menu. You must then click in the drawing area
to fix the position of the relationship, where any relationship symbol will
appear.
 | During
the relationship creation MetaEdit+ always checks if it is possible to add more
roles. If the current relationship type in the current graph type does not allow
any more connections than the relationship already has, MetaEdit+ does not offer
to add more connections (i.e. if a language only has binary relationships, the
user will never be prompted to add a third
role). |
Advanced use of the toolbar while creating relationships
The type toolbar provides two useful options for easing the
creation of relationships in certain situations. The first such option is the
generic relationship button (as shown in
Figure 4–3) that initiates the
creation of any relationship type. The type for the created relationship is
determined from context, or the user is prompted to choose between legal
relationship types in that context when the creation is confirmed.
The other option is the sticky mode for relationship
creation, which can be enabled by holding down the
Ctrl key when
selecting the relationship type. This enables the user to create several
relationships of the same type sequentially, without needing to re-select the
relationship type after each one is created. The sticky mode is retained until a
new type is selected or the right mouse button is pressed to cancel the creation
of a relationship. Sticky mode applies also to the generic relationship
creation.
Moving relationships
As with objects, relationships can be moved. To do
this:
1) | Click
on the relationship with the left mouse button.
|
 | If
the relationship has no symbol, click on the red dot that indicates its
position. If it has a symbol that is currently not visible (e.g. an empty string
property), you can find the relationship’s point by default as the
midpoint of the role
lines. |
2) | Drag
the relationship to a new location. |
The
relationship symbol can be moved to the midpoint between its objects, and all
existing break points in all roles of the relationship can be removed by
selecting Straighten Relationship (or Straighten Relationship(s)
if you have selected multiple relationships) from the pop-up menu of the
relationship. Normally, this will not affect the target points of roles, but if
Shift is held down it will also reset the target points.
It is also possible to move straight binary relationships
so that their straightness is preserved, i.e. the target points at the end of
both roles are also moved in relation to the position of the relationship (as in
Figure 4–14). This can be done by
holding down the
Ctrl and
Shift keys while moving the
relationship.

Figure 4–14. Moving straight binary relationships.
Scaling
relationship symbols and aligning them to the grid is described at the end of
Section
4.1.6.
Editing role properties
Relationships are connected to objects through roles. Each
relationship has at least two roles and they too can have properties. An example
of a property for a role is a cardinality constraint in an
Entity-Relationship-Attribute Diagram.
Because roles are attached to relationships their
management is closely related to the management of relationships. When a
relationship is created, you are also asked for values for its roles, and when a
relationship is removed the roles too are removed.
Property dialogs for roles can be accessed as with
relationships. To edit role properties:
1) | Select
the role by clicking it with the left mouse button. The ends of the role, and
any breakpoints along it, are marked with small squares. Figure 4–15 below shows the Diagram
Editor with a role
selected. |
2) | Open
the pop-up menu with the right mouse button.
|
3) | Select
Properties... and the property dialog
opens. |
 | As
in other editors, you may also press Enter or double-click to open the
property dialog for the selected
role. |
Working with role breakpoints and target
points
Roles consist of a line, possibly with breakpoints along the
line, and a target point at the end of the line where the role connects to the
object (
Figure 4–15). Normally
the breakpoints and target point move together with the relationship and
objects, but it is also possible to move them separately.
For target points, it is important to understand that they
do not lock the end of the role line at a certain fixed point in the drawing
area. Rather, role lines aim at target points, which are specified as offsets
from the centre of the object’s connectable. This means while moving or
scaling an object with roles that have specified target points, the role lines
stay aimed at those target points, but do not necessarily stop at the target
point. Role lines are always drawn to stop where they cut the object’s
connectable. If a line aimed at the target point will not cut the object
connectable, the target point is ignored and the line is retargeted to the
closest point on the connectable.
To add a new breakpoint to an existing role
line:
1) | Select
the role line by clicking
it. |
2) | Move
the cursor over the role line at the point where you want to add the
breakpoint. |
3) | Press
and hold down the left mouse button and drag the new breakpoint to its desired
location. |
Or |
1) | Select
the role line by clicking
it. |
2) | Select
Add Point from the role line’s pop-up
menu. |
You can remove a breakpoint either
by control-clicking it or by choosing Delete Point from its pop-up menu.
All existing break points in all roles of a relationship can be removed by
selecting Straighten Role from the pop-up menu of the relationship.
Normally, this will not affect the target point, but if Shift is held
down it will also reset the target point.

Figure 4–15. Breakpoints and target point.
To move
the target points, drag them along the symbol perimeter (as in the lower part of
Figure 4–15). If the current
selection includes multiple roles, dragging one role’s target point drags
the target points of all selected roles attached to that object — useful
in Sequence Diagrams. To restore a target point into its original position,
control-click it or select
Restore Target Point from its pop-up
menu.
Adding, deleting and reconnecting roles
You can add a new role to the relationship by selecting it and
choosing Add a New Role... from its pop-up menu. An alternative way to
add a role is to activate the respective relationship creation from the type
toolbar, then click left mouse button on the relationship you want add a role to
(the relationship must be of the same type as selected in the toolbar) and then
drag the role line on the target object.
Roles can be deleted either by pressing the Delete key
when the role is selected, by choosing Delete from the pop-up menu or
toolbar or by selecting Edit | Delete. Note that if the relationship will
be left with fewer than two roles the relationship is removed as well.
It is also possible to reconnect a role from one object to
another, or to a different port. To do this, select the role then hold down
Shift and drag its target point handle from the current object to the new
object or port. Alternatively, you can select Reconnect from the
role’s target point’s pop-up menu. Unlike the Shift-drag method,
selecting Reconnect from the menu will also discard any existing
breakpoints along that role line; to keep them, hold down Shift when
selecting from the menu. You can cancel the reconnect in either method by
right-clicking.
If reconnecting was not possible with the original role,
but a role of a different type would work, MetaEdit+ will prompt you to select
that type.
Deleting relationships
To delete a relationship, either press the Delete key when the
relationship is selected, choose
Delete from the relationship’s
pop-up menu or toolbar, or select
Edit | Delete. When a relationship is
deleted its roles are also deleted.