Inheritance of relates roles [TYW34] Invalid Type Write

Hi all,

I got an error which I do not completely understand:

[TYW34] Invalid Type Write: The role type 'relation102:role10' cannot be used as an alias for the inherited role type 'relation100:role10' - use the inherited role type or define a new role type overriding it with a new name.

The schema looks like this

relation100 sub relation, relates role10
relation101 sub relation100, plays relation2:role2
relation102 sub relation101, plays relation3:role3

entity1 sub entity, plays relation102:role10

The error is thrown when defining this last entity1. So my question is, can one not use the inherited relates role ‘role10’ for all its children relations when defining a play role in one of them?

Maybe I’m missing something, but I thought basically that the relates role gets just inherited along the line and that an entity could play a role in relation102 with that inherited relates role ‘role10’. Also when defining a relation with relation101, I get the error:

Invalid Type Write: The role type 'relation101:role10' cannot be used as an alias for the inherited role type 'relation100:role10' - use the inherited role type or define a new role type overriding it with a new name.

So this would imply that an object can only play role10 in relation100 but not in relation101 or relation102, but then I think I’m really lacking an understanding of what it means to pass on ‘relates roles’ (or inherit relates roles respectively)

Would be great to here your opinion on that! :slight_smile:

Many thanks!

1 Like

Hi @c-lare ,

In TypeDB every schema type (entity, relation, attribute and role) is identified by a unique identifier (the label) and can only be referred by that specific label. Your understanding is correct that relation102 implicitly relates role10 by inheritance. But when referring to the role type in your schema, you’ll need to use the exact label that was defined for it, relation100:role10.

(relation100:role10 is a scoped label, and it requires the correct scope (relation100) in order to be valid. role10 is an unscoped label, and is valid in more contexts: e.g. match $r (role10: $x) isa relation;)

1 Like

To add to @alex’s answer, saying that entity1 plays relation100:role10 would allow instances of it to play role10 in relation100, relation101, relation102, or any other relation that inherits the role. If you would like to permit entity1 to play a role only in relation102, then you’ll need to override the role as follows:

relation100 sub relation, relates role10;
relation101 sub relation100, plays relation2:role2;
relation102 sub relation101,
  relates role10-2 as role10,
  plays relation3:role3;

entity1 sub entity, plays relation102:role10-2;
1 Like

Amazing, thank you both, makes total sense now! :slight_smile: