Show a relationship by nesting

Intermediate

How to show a relationship by drawing one element inside another instead of as a line: allow nesting on a relationship type, nest elements on a diagram, and take them out again.

Some modelling languages let you show a relationship by drawing one element inside another instead of drawing a line between them. In ArchiMate, for example, an application component drawn inside another usually means Composition. Metapad supports this notation for any relationship type you choose.

Nesting is only a way of drawing. The relationship is a normal relationship in your model: the Model Navigator tree does not change, and other diagrams can still show it as a line. If you want an element to really belong to its container, so that it appears beneath it in the tree and you can double-click into the container, use Containment instead (see Type Hierarchy: Inheritance, Containment & Aggregation).

1. Allow nesting for a relationship type

  1. Select the relationship type in the Model Navigator.
  2. In the Properties panel, turn on Shown by nesting.
  3. Under Outer element, choose which end is drawn on the outside:
    • Source: the relationship goes from the outer element to the inner one. Composition works this way: the whole contains its part.
    • Target: the relationship goes from the inner element to the outer one. Assignment drawn as nesting works this way.

If elements already lie completely inside their partner on your diagrams when you turn on Shown by nesting, they are nested straight away. One Undo takes it back.

A relationship type can't be shown by nesting and be a containment relationship at the same time. Turn one off before turning the other on.

2. Nest an element on a diagram

Drag an element so that it lies completely inside another one. This works for elements you move on the canvas, new elements from the Toolbox and elements dragged from the Model Navigator. What happens next depends on your model:

SituationWhat Metapad does
A relationship of a nesting type already connects the twoNests the element. If the relationship was drawn, its line disappears.
No such relationship yet, and exactly one nesting type is allowed between themAsks Create Composition from 'A' to 'B'? Click Create to add the relationship and nest the element.
Several nesting types are allowedAsks which relationship the nesting should stand for. Pick one, and it is created in the right direction.
No nesting type is allowed between themNothing is nested. The element simply lies on top of the other.

Click Cancel, or press Esc, to leave the element on top without creating anything.

Other relationships between the two elements follow their type's Hide line when nested setting (see below). It is on by default, so their lines are hidden too while the element lies inside.

3. Take an element out again

Drag the nested element out of its container. The relationship stays in your model, and its line is drawn again. If you don't want the line, hide it as usual.

Hiding lines without nesting: "Hide line when nested"

Every relationship type has a setting Hide line when nested, which is on by default. While one element lies completely inside the other on a diagram, at any depth, the line between them is not drawn. Drag the element out and the line appears again. Nothing in your model changes; it only affects how the diagram is drawn.

Turn it off in the relationship type's Properties for lines you always want to see. In ArchiMate, for example, a Serving between an element and the box it sits in is usually still drawn.

For types that are Shown by nesting, the setting is always on and cannot be changed.

Good to know

  • Undo takes back the whole step in one go: the move, the nesting and a relationship that was just created.
  • Moving the outer element moves everything inside it.
  • Nesting is saved with the diagram and seen by your collaborators straight away.
  • Assistants and tools that work over the API can nest elements too.

This content was written collaboratively with AI.