Officially out now: The TypeDB 3.0 Roadmap >>

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

Syntax
<type> owns <attribute-type> [<annotation>] [as <overridden-type>];

For more information about annotations, see the @key and @unique pages.

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 query example
define
pdf sub file, owns name;

To remove the ability to own attributes of the name type, but keep the pdf type, use:

Undefine query example
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:

Override owned attribute type example
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;

Learn more

Learn more about type statement in TypeQL.

Learn about types in TypeQL.