TypeDB 3.0 is live! Get started for free.

relates statement

The statement <RELATION LABEL> relates <LABEL> is used to identify the <LABEL> as a role type related by <RELATION LABEL>.

It can be extended to <RELATION LABEL> relates <LABEL> as <SPECIALIZED LABEL> to specify specialization between two role types. SPECIALIZED LABEL> should be inherited by <RELATION LABEL> from a supertype. <LABEL> becomes a subtype of <SPECIALIZED LABEL>, and the <RELATION LABEL> instances do no longer accept role players of <SPECIALIZED LABEL>. <LABEL> is called specializing relates, and <SPECIALIZED LABEL> is called specialized relates.

Defining role types

The relates keyword can be used to define a role type for a relation type.

define parentship relates parent;

Defining specializing role types

The relates …​ as construction can be used to define a role type specializing an inherited role type.

define fathership relates father as parent;

Redefining specializing role types

The relates …​ as construction can be used to define a role type specializing an inherited role type.

redefine fathership relates father as child;

Undefining role types

The relates keyword can be used to undefine a role type from a relation.

undefine relates parent from parentship;

Undefining role types specialization

The relates …​ as construction can be used to undefine a role type specialization.

undefine as parent from fathership relates father;

Matching

The relates keyword can be used to match all role types related by a relation type.

match parentship relates $r;

Matching relation types

The relates keyword can be used to match all relation types for a role type with a label <LABEL>.

match $r relates parent;

Note that a scope can be used to have more specific results. The previous query can return results for different role types with the same <LABEL>, while the following example returns only relation types with the specified scope.

match $r relates parentship:parent;