diff --git a/src/content/doc-surrealql/datamodel/ids.mdx b/src/content/doc-surrealql/datamodel/ids.mdx index d9bcef4d1..42c9d8009 100644 --- a/src/content/doc-surrealql/datamodel/ids.mdx +++ b/src/content/doc-surrealql/datamodel/ids.mdx @@ -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>; +DEFINE FIELD friends ON TABLE person TYPE option>>; + +CREATE person SET + possessions = [ book:one, house:one], + friends = [ person:one, person:two ]; +``` + +Be sure to use just `record` instead of `record`, as `` here would imply actual records of a table called `any`. + +```surql +DEFINE FIELD possessions ON TABLE person TYPE option>>; + +-- 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).