From 06b561e5f982b5a0aa947a214da1e7de63fc5bcb Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 25 Jan 2026 17:29:24 +0100 Subject: [PATCH] fix handling of a single column unique index with externalIdMapping --- packages/server/src/api/rest/index.ts | 2 +- packages/server/test/api/rest.test.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/rest/index.ts b/packages/server/src/api/rest/index.ts index 980af6ba7..c2723f061 100644 --- a/packages/server/src/api/rest/index.ts +++ b/packages/server/src/api/rest/index.ts @@ -1344,7 +1344,7 @@ export class RestApiHandler implements Api if (name === externalIdName) { if (typeof info.type === 'string') { // single unique field - return [this.requireField(model, info.type)]; + return [this.requireField(model, name)]; } else { // compound unique fields return Object.keys(info).map((f) => this.requireField(model, f)); diff --git a/packages/server/test/api/rest.test.ts b/packages/server/test/api/rest.test.ts index 96b469ba7..ec0a6a8a9 100644 --- a/packages/server/test/api/rest.test.ts +++ b/packages/server/test/api/rest.test.ts @@ -3183,6 +3183,7 @@ describe('REST server tests', () => { model Post { id Int @id @default(autoincrement()) title String + short_title String @unique() author User? @relation(fields: [authorId], references: [id]) authorId Int? } @@ -3195,6 +3196,7 @@ describe('REST server tests', () => { endpoint: 'http://localhost/api', externalIdMapping: { User: 'name_source', + Post: 'short_title', }, }); handler = (args) => _handler.handleRequest({ ...args, url: new URL(`http://localhost/${args.path}`) }); @@ -3229,13 +3231,13 @@ describe('REST server tests', () => { expect(r.body.data.attributes.name).toBe('User1'); await client.post.create({ - data: { id: 1, title: 'Title1', authorId: 1 }, + data: { id: 1, title: 'Title1', short_title: 'post-title-1', authorId: 1 }, }); // post is exposed using the `id` field r = await handler({ method: 'get', - path: '/post/1', + path: '/post/post-title-1', query: { include: 'author' }, client, });