6.7.2 Loop-backs
Navigating via a relationship while navigating through
bindings may sometimes produce unexpected results. Consider the following
expression when navigating from an object:
do >Transition.()
What we probably wanted to do
with this was to access all objects that the current object is connected to via
a ‘Transition’ relationship. However, navigating to the relationship
leaves us ‘in’ that relationship, and when we try to navigate from
there to objects, we can get to not only the object we wanted, but also back to
the object we started from.
The simplest solution is to specify the role types,
effectively making the relationship directed:
do ~From>Transition~To.()
If those role types are
not used with other relationship types, it is also possible to omit the
relationship entirely, and navigate from the From role to all To roles contained
in the same binding:
do ~From~To.()
Even if the role types at either end
of this binding are of the same type, this is still possible. Navigating in one
step from a role to roles, there is no way to get from the role back to itself.
For instance, if there is an Association relationship with just Involved
roles:
do ~Involved~Involved.()
If there is a need to check
the type of the relationship in this kind of construction, remember that we
cannot insert >Association between the roles. That would bring us back to the
same problem we started with, i.e. from the Association we could get back to the
same Involved role we came from. Instead, we can check the relationship type
with an if statement:
do ~Involved~Involved
{ if >Association then
do .()
{ ... }
endif
}