Skip to content

Commit

Permalink
Show what type records are inside a schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhghomon committed Jan 9, 2025
1 parent 00e840f commit 7dd7307
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/content/doc-surrealql/datamodel/ids.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ COMMIT TRANSACTION;
RETURN person_id:counter.num;
```

## Defining record IDs in a schema

The type name of a record ID is `record`, which by default allows any sort of record.

```surql
DEFINE FIELD possessions ON TABLE person TYPE option<array<record>>;
DEFINE FIELD friends ON TABLE person TYPE option<array<record<person>>>;
CREATE person SET
possessions = [ book:one, house:one],
friends = [ person:one, person:two ];
```

Be sure to use just `record` instead of `record<any>`, as `<any>` here would imply actual records of a table called `any`.

```surql
DEFINE FIELD possessions ON TABLE person TYPE option<array<record<any>>>;
-- Won't work, 'book' and 'house' are not of table 'any'
CREATE person SET
possessions = [ book:one, house:one ];
-- Actually expects this, which is probably
-- not what the DEFINE FIELD intended
CREATE person SET
possessions = [ any:one, any:two ];
```

## Learn more

Learn more about Record IDs [in this blogpost](/blog/the-life-changing-magic-of-surrealdb-record-ids#the-performance-at-scale) and on this [youtube video](https://www.youtube.com/watch?v=c0cqmWRYP8c).

0 comments on commit 7dd7307

Please sign in to comment.