Skip to content

Commit f2c567b

Browse files
authored
fix(orm): _count is not included in select clause's typing when querying from a to-one relation (#2403)
1 parent 89e3acb commit f2c567b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/orm/src/client/crud-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ export type FindArgs<
12151215
: {})
12161216
: {}) &
12171217
(AllowFilter extends true ? FilterArgs<Schema, Model, Options> : {}) &
1218-
SelectIncludeOmit<Schema, Model, Collection, Options>;
1218+
SelectIncludeOmit<Schema, Model, true, Options>;
12191219

12201220
export type FindManyArgs<
12211221
Schema extends SchemaDef,

tests/e2e/orm/client-api/find.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,27 @@ describe('Client find tests ', () => {
11201120
).resolves.toMatchObject({
11211121
_count: { posts: 0 },
11221122
});
1123+
1124+
// typing
1125+
// user select allows _count because it has to-many relations
1126+
client.user.findMany({
1127+
select: { _count: { select: { posts: true } } },
1128+
});
1129+
// nested author select allows _count because it has to-many relations
1130+
client.post.findMany({
1131+
select: {
1132+
author: {
1133+
select: {
1134+
_count: { select: { posts: true } },
1135+
},
1136+
},
1137+
},
1138+
});
1139+
// comment select does not allow _count because it has no to-many relations
1140+
client.comment.findMany({
1141+
// @ts-expect-error
1142+
select: { _count: {} },
1143+
});
11231144
});
11241145

11251146
it('supports _count inside include', async () => {

0 commit comments

Comments
 (0)