From 47357f64edc028308786ee9a5f42d57456572ff5 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Fri, 8 Aug 2025 11:33:01 +0200 Subject: [PATCH] document externalIdMapping --- .../server-adapters/api-handlers/rest.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/reference/server-adapters/api-handlers/rest.mdx b/docs/reference/server-adapters/api-handlers/rest.mdx index 67365c6f..867e7a43 100644 --- a/docs/reference/server-adapters/api-handlers/rest.mdx +++ b/docs/reference/server-adapters/api-handlers/rest.mdx @@ -99,6 +99,21 @@ The factory function accepts an options object with the following fields: 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. +- externalIdMapping + + Optional. An `Record` 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: + + ```ts + // Expose tags by unique name and not by ID, ie. /tag/blue intead of /tag/id + RestApiHandler({ + externalIdMapping: { + Tag: 'name' + } + }) + ``` + + 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). + ## Endpoints and Features