Skip to content

Commit 10b0755

Browse files
authored
document externalIdMapping (#480)
1 parent e9f0855 commit 10b0755

File tree

1 file changed

+15
-0
lines changed
  • docs/reference/server-adapters/api-handlers

1 file changed

+15
-0
lines changed

docs/reference/server-adapters/api-handlers/rest.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ The factory function accepts an options object with the following fields:
9999

100100
The mapping can be partial. You only need to specify the model names that you want to override. If a mapping is provided, only the mapped url path is valid, and accessing to unmapped path will be denied.
101101

102+
- externalIdMapping
103+
104+
Optional. An `Record<string, string>` value that provides a mapping from model names (as defined in ZModel) to unique contraint name. This is useful when you for example want to expose natural keys in place of a surrogate keys:
105+
106+
```ts
107+
// Expose tags by unique name and not by ID, ie. /tag/blue intead of /tag/id
108+
RestApiHandler({
109+
externalIdMapping: {
110+
Tag: 'name'
111+
}
112+
})
113+
```
114+
115+
Currentlly it is not possible to use custom index names. This also works for compound unique contraints just like for [compound IDs](#compound-id-fields).
116+
102117

103118
## Endpoints and Features
104119

0 commit comments

Comments
 (0)