Skip to content

Commit 002e132

Browse files
authored
fix(rest): multiple relation id filter values are not properly split (#2085)
1 parent c58d887 commit 002e132

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,12 @@ class RequestHandler extends APIHandlerBase {
17501750
: this.makePrismaIdFilter(info.idFields, value, false);
17511751
return { some: filterValue };
17521752
} else {
1753-
return { is: this.makePrismaIdFilter(info.idFields, value, false) };
1753+
const values = value.split(',').filter((i) => i);
1754+
if (values.length > 1) {
1755+
return { OR: values.map((v) => this.makePrismaIdFilter(info.idFields, v, false)) };
1756+
} else {
1757+
return { is: this.makePrismaIdFilter(info.idFields, value, false) };
1758+
}
17541759
}
17551760
} else {
17561761
const coerced = this.coerce(fieldInfo.type, value);

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

+9
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,15 @@ describe('REST server tests', () => {
664664
expect(r.body.data).toHaveLength(1);
665665
expect(r.body.data[0]).toMatchObject({ id: 1 });
666666

667+
// relation filter with multiple values
668+
r = await handler({
669+
method: 'get',
670+
path: '/post',
671+
query: { ['filter[author]']: 'user1,user2' },
672+
prisma,
673+
});
674+
expect(r.body.data).toHaveLength(2);
675+
667676
// invalid filter field
668677
r = await handler({
669678
method: 'get',

0 commit comments

Comments
 (0)