From 070cf5db162f31c9e7d93c8f4b214b4a3d34fd00 Mon Sep 17 00:00:00 2001 From: Dave MacLeod <56599343+Dhghomon@users.noreply.github.com> Date: Fri, 3 Jan 2025 15:14:48 +0900 Subject: [PATCH] Record links example --- src/content/doc-surrealql/datamodel/idioms.mdx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/content/doc-surrealql/datamodel/idioms.mdx b/src/content/doc-surrealql/datamodel/idioms.mdx index ac7b56c62..f25bde416 100644 --- a/src/content/doc-surrealql/datamodel/idioms.mdx +++ b/src/content/doc-surrealql/datamodel/idioms.mdx @@ -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 │ │ ▲ @@ -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.