Links

Links define a specific relationship between two object types. Links have a direction, but can be traversed in both ways forward and backward.

To define a relationship we use the link keyword:

Copy
type Movie {
    required property title -> str;
    required link director -> Person;
    multi link actors -> Person;
}
type Person {
    required property first_name -> str;
    required property last_name -> str;
}

Links allow fetching relationships with a single query:

Copy
tutorial> 
......... 
......... 
......... 
select Movie {
   director: { first_name },
   actors: { first_name },
};
{
    Object {
        director: Object { first_name: 'Denis' },
        actors: {
            Object { first_name: 'Harrison' },
            Object { first_name: 'Ryan' },
            Object { first_name: 'Ana' },
        }
    }
}

Similarly you can run some aggregates on the nested sets:

Copy
tutorial> 
SELECT Movie { title, actors_number:=count(.actors) };
{Object { title: 'Blade Runner 2049', actors_number: 3 }}

You can find more information on aggregates in the Cookbook and the reference of set functions (or just search for “aggregate”).

Light
Dark
System