Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ export class RestApiHandler<Schema extends SchemaDef = SchemaDef> 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));
Expand Down
6 changes: 4 additions & 2 deletions packages/server/test/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand All @@ -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}`) });
Expand Down Expand Up @@ -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,
});
Expand Down
Loading