Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 14a0a03

Browse files
authored
fix handling of a single column unique index with externalIdMapping (#612)
1 parent f612723 commit 14a0a03

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

packages/server/src/api/rest/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ export class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Api
13441344
if (name === externalIdName) {
13451345
if (typeof info.type === 'string') {
13461346
// single unique field
1347-
return [this.requireField(model, info.type)];
1347+
return [this.requireField(model, name)];
13481348
} else {
13491349
// compound unique fields
13501350
return Object.keys(info).map((f) => this.requireField(model, f));

packages/server/test/api/rest.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,7 @@ describe('REST server tests', () => {
31833183
model Post {
31843184
id Int @id @default(autoincrement())
31853185
title String
3186+
short_title String @unique()
31863187
author User? @relation(fields: [authorId], references: [id])
31873188
authorId Int?
31883189
}
@@ -3195,6 +3196,7 @@ describe('REST server tests', () => {
31953196
endpoint: 'http://localhost/api',
31963197
externalIdMapping: {
31973198
User: 'name_source',
3199+
Post: 'short_title',
31983200
},
31993201
});
32003202
handler = (args) => _handler.handleRequest({ ...args, url: new URL(`http://localhost/${args.path}`) });
@@ -3229,13 +3231,13 @@ describe('REST server tests', () => {
32293231
expect(r.body.data.attributes.name).toBe('User1');
32303232

32313233
await client.post.create({
3232-
data: { id: 1, title: 'Title1', authorId: 1 },
3234+
data: { id: 1, title: 'Title1', short_title: 'post-title-1', authorId: 1 },
32333235
});
32343236

32353237
// post is exposed using the `id` field
32363238
r = await handler({
32373239
method: 'get',
3238-
path: '/post/1',
3240+
path: '/post/post-title-1',
32393241
query: { include: 'author' },
32403242
client,
32413243
});

0 commit comments

Comments
 (0)