-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delegate): support _count select of base fields (#1937)
- Loading branch information
Showing
3 changed files
with
217 additions
and
39 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
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
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,51 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('issue 1467', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model User { | ||
id Int @id @default(autoincrement()) | ||
type String | ||
@@allow('all', true) | ||
} | ||
model Container { | ||
id Int @id @default(autoincrement()) | ||
drink Drink @relation(fields: [drinkId], references: [id]) | ||
drinkId Int | ||
@@allow('all', true) | ||
} | ||
model Drink { | ||
id Int @id @default(autoincrement()) | ||
name String @unique | ||
containers Container[] | ||
type String | ||
@@delegate(type) | ||
@@allow('all', true) | ||
} | ||
model Beer extends Drink { | ||
@@allow('all', true) | ||
} | ||
` | ||
); | ||
|
||
const db = enhance(); | ||
|
||
await db.beer.create({ | ||
data: { id: 1, name: 'Beer1' }, | ||
}); | ||
|
||
await db.container.create({ data: { drink: { connect: { id: 1 } } } }); | ||
await db.container.create({ data: { drink: { connect: { id: 1 } } } }); | ||
|
||
const beers = await db.beer.findFirst({ | ||
select: { id: true, name: true, _count: { select: { containers: true } } }, | ||
orderBy: { name: 'asc' }, | ||
}); | ||
expect(beers).toMatchObject({ _count: { containers: 2 } }); | ||
}); | ||
}); |