Skip to content

Commit ba8bf68

Browse files
Fix for filtering by compound id
In some cases Prisma doesn’t expect these to be nested under the compound id key.
1 parent fac631b commit ba8bf68

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,11 @@ class RequestHandler extends APIHandlerBase {
12361236
return r.toString();
12371237
}
12381238

1239-
private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string) {
1239+
private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string, nested: boolean = true) {
12401240
const decodedId = decodeURIComponent(resourceId);
12411241
if (idFields.length === 1) {
12421242
return { [idFields[0].name]: this.coerce(idFields[0].type, decodedId) };
1243-
} else {
1243+
} else if (nested) {
12441244
return {
12451245
// TODO: support `@@id` with custom name
12461246
[idFields.map((idf) => idf.name).join(prismaIdDivider)]: idFields.reduce(
@@ -1251,6 +1251,14 @@ class RequestHandler extends APIHandlerBase {
12511251
{}
12521252
),
12531253
};
1254+
} else {
1255+
return idFields.reduce(
1256+
(acc, curr, idx) => ({
1257+
...acc,
1258+
[curr.name]: this.coerce(curr.type, decodedId.split(this.idDivider)[idx]),
1259+
}),
1260+
{}
1261+
);
12541262
}
12551263
}
12561264

@@ -1598,7 +1606,7 @@ class RequestHandler extends APIHandlerBase {
15981606
: this.makePrismaIdFilter(info.idFields, value);
15991607
return { some: filterValue };
16001608
} else {
1601-
return { is: this.makePrismaIdFilter(info.idFields, value) };
1609+
return { is: this.makePrismaIdFilter(info.idFields, value, false) };
16021610
}
16031611
} else {
16041612
const coerced = this.coerce(fieldInfo.type, value);

0 commit comments

Comments
 (0)