Skip to content

Commit

Permalink
Record links example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhghomon committed Jan 3, 2025
1 parent 75de1c9 commit 070cf5d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/content/doc-surrealql/datamodel/idioms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,8 @@ RELATE person:acquaintance3->knows->person:star;
This representation of this small network of friends allows us to visualize the issues that these three algorithms solve. Using `+path` will output all of the possible paths from `person:you`, `+collect` will collect all of the records in this network, and `+shortest=person:star` will find the shortest path.

```
┌───────► person:friend1 ┌───►person:acquaintance1
┌───────► person:friend1
┌───►person:acquaintance1 │
│ │ │
│ │ ┼───►person:acquaintance2 person:star
person:you │ │ ▲
Expand Down Expand Up @@ -1415,6 +1416,20 @@ person:you.{..1+path}->knows->person;
]
```

As is the case with other recursive queries, these three algorithms can be used in the same way with any other repeating path, such as record links. The following example shows the same network of friends as the one above, except that it uses record links instead of graph queries. To traverse these paths, a simple `.knows` is all that is required.

```surql
CREATE person:you SET knows = [person:friend1, person:friend2];
CREATE person:friend1 SET knows = [person:friend2];
CREATE person:friend2 SET knows = [person:acquaintance1, person:acquaintance2, person:acquaintance3];
CREATE person:acquaintance1, person:acquaintance2, person:star;
CREATE person:acquaintance3 SET knows = [person:star];
person:you.{..+shortest=person:star}.knows;
person:you.{..+path}.knows;
person:you.{..+collect}.knows;
```

## Combining Idiom Parts

Idioms can combine multiple parts to navigate complex data structures seamlessly.
Expand Down

0 comments on commit 070cf5d

Please sign in to comment.