owns
The owns
keyword is used in TypeQL schema to define an owner type for an attribute type.
Syntax
The syntax of a owns
statement includes:
-
Subject — type label of the owner type
-
Predicate — the
owns
keyword -
Object — type label of an attribute type
<type> owns <attribute-type> [<annotation>] [as <overridden-type>];
An optional override can be added at the end.
Behavior
TypeQL statements with the owns
keyword can be used only in Define and Undefine queries.
The owns
keyword adds an ability for the subject type to own attributes of
the object attribute type to the schema.
Usage in a schema definition
For this example, use a database with the IAM schema and sample data loaded.
Since in Define and Undefine queries you can’t use variables, both subject and object can only be type labels.
For example, to define a new type pdf
with an ability to own attributes of the name
attribute type, use:
define
pdf sub file, owns name;
To remove the ability to own attributes of the name
type, but keep the pdf
type, use:
undefine
pdf owns name;
Usage with override
For this example, use a database with the IAM schema and sample data loaded.
By default, a subtype inherits all attribute types that were defined as owned for its supertype.
To override an inherited attribute type ownership, use the as
keyword when defining an ownership.
The overridden attribute type must be a subtype of the inherited attribute type.
Let’s see an example, of a schema, where the name
attribute type gets overridden by the full-name
attribute:
define
name sub attribute, abstract, value string;
full-name sub name;
person sub entity, abstract, owns name;
user sub person, owns full-name as name;