I’m trying to understand how to correctly override a “plays role”. In the documentation, it says:
By default, a subtype of a relation type inherits all roles that were defined for its supertype. To override an inherited role, use the as keyword. The overridden new role must be a subtype of the inherited role.
What I do not understand is the part about " The overridden new role must be a subtype of the inherited role." I did not come across any subtyping of roles as roles are not standalone defined concepts. So how can one sub-type a role and use it as the overriding role? It would be great if someone could provide me with a testable example
base-relation sub relation, relates base-role;
sub-relation sub base-relation, relates sub-role as base-role;
Here, sub-role is a subtype of base-role. Overriding a role means the inherited role is ‘hidden’ i.e., you can no longer insert (base-relation: $x) isa sub-relation
base-entity sub entity, plays base-relation:base-role;
sub-entity sub base-entity, plays sub-role as base-role;
This would override the role. I believe the override removes the ability for sub-entity to play base-entity:base-role
One follow-up question (I adapted your code a bit to match the TypeDB documentation for plays roles
If I use this schema definition:
base-relation sub relation, relates base-role;
sub-relation sub base-relation, relates sub-role as base-role;
base-entity sub entity, plays base-relation:base-role;
sub-entity sub base-entity, plays sub-relation:sub-role as base-role;
sub-entity basically plays only one role “sub-role” and not “base-role” anymore? And when I use it without overriding, like so:
base-relation sub relation, relates base-role;
sub-relation sub base-relation, relates sub-role as base-role;
base-entity sub entity, plays base-relation:base-role;
sub-entity sub base-entity, plays sub-relation:sub-role;
it basically can play base-role and sub-role? If that is the case, I think I understand it then.
Just a second quick follow-up: If you have a practical example where one would not want to override (so allow it to play both roles), that would be great!
Many thanks! Just to get it right. Can sub-entity play base-role in base-relation if it was not overridden e.g. with “plays sub-relation:sub-role as base-role;” and I only have “plays sub-relation:sub-role;”? I was just assuming that “plays sub-relation:sub-role as base-role;” is still inherited and we add a new playing role “plays sub-relation:sub-role;”
Or with other words, when using:
base-entity sub entity, plays base-relation:base-role;
sub-entity sub base-entity, plays sub-relation:sub-role;
sub-entity can play base role in base relation and sub role in sub relation?