-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(polymorphism): wrong query result when selecting "_count"
Fixes #1123
- Loading branch information
Showing
2 changed files
with
83 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/integration/tests/enhancements/with-delegate/issue-1123.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('Regression for issue 1123', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model Content { | ||
id String @id @default(cuid()) | ||
published Boolean @default(false) | ||
contentType String | ||
likes Like[] | ||
@@delegate(contentType) | ||
@@allow('all', true) | ||
} | ||
model Post extends Content { | ||
title String | ||
} | ||
model Image extends Content { | ||
url String | ||
} | ||
model Like { | ||
id String @id @default(cuid()) | ||
content Content @relation(fields: [contentId], references: [id]) | ||
contentId String | ||
@@allow('all', true) | ||
} | ||
` | ||
); | ||
|
||
const db = enhance(); | ||
await db.post.create({ | ||
data: { | ||
title: 'a post', | ||
likes: { create: {} }, | ||
}, | ||
}); | ||
|
||
await expect(db.content.findFirst({ include: { _count: { select: { likes: true } } } })).resolves.toMatchObject( | ||
{ | ||
_count: { likes: 1 }, | ||
} | ||
); | ||
}); | ||
}); |