-
-
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): nested create/connect in delegate model requires refer…
…ence fields fixes #1894
- Loading branch information
Showing
2 changed files
with
90 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('issue 1894', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model A { | ||
id Int @id @default(autoincrement()) | ||
b B[] | ||
} | ||
model B { | ||
id Int @id @default(autoincrement()) | ||
a A @relation(fields: [aId], references: [id]) | ||
aId Int | ||
type String | ||
@@delegate(type) | ||
} | ||
model C extends B { | ||
f String? | ||
} | ||
`, | ||
{ | ||
enhancements: ['delegate'], | ||
compile: true, | ||
extraSourceFiles: [ | ||
{ | ||
name: 'main.ts', | ||
content: ` | ||
import { enhance } from '.zenstack/enhance'; | ||
import { PrismaClient } from '@prisma/client'; | ||
async function main() { | ||
const db = enhance(new PrismaClient()); | ||
await db.a.create({ data: { id: 0 } }); | ||
await db.c.create({ data: { a: { connect: { id: 0 } } } }); | ||
} | ||
main(); | ||
`, | ||
}, | ||
], | ||
} | ||
); | ||
|
||
const db = enhance(); | ||
await db.a.create({ data: { id: 0 } }); | ||
await expect(db.c.create({ data: { a: { connect: { id: 0 } } } })).toResolveTruthy(); | ||
}); | ||
}); |