-
-
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): relation name disambiguation (#1107)
- Loading branch information
Showing
5 changed files
with
133 additions
and
6 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
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
69 changes: 69 additions & 0 deletions
69
tests/integration/tests/enhancements/with-delegate/issue-1100.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,69 @@ | ||
import { loadModelWithError, loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('Regression for issue 1100', () => { | ||
it('missing opposite relation', async () => { | ||
const schema = ` | ||
model User { | ||
id String @id @default(cuid()) | ||
name String? | ||
content Content[] | ||
post Post[] | ||
} | ||
model Content { | ||
id String @id @default(cuid()) | ||
published Boolean @default(false) | ||
contentType String | ||
@@delegate(contentType) | ||
user User @relation(fields: [userId], references: [id]) | ||
userId String | ||
} | ||
model Post extends Content { | ||
title String | ||
} | ||
model Image extends Content { | ||
url String | ||
} | ||
`; | ||
|
||
await expect(loadModelWithError(schema)).resolves.toContain( | ||
'The relation field "post" on model "User" is missing an opposite relation field on model "Post"' | ||
); | ||
}); | ||
|
||
it('success', async () => { | ||
const schema = ` | ||
model User { | ||
id String @id @default(cuid()) | ||
name String? | ||
content Content[] | ||
post Post[] | ||
} | ||
model Content { | ||
id String @id @default(cuid()) | ||
published Boolean @default(false) | ||
contentType String | ||
@@delegate(contentType) | ||
user User @relation(fields: [userId], references: [id]) | ||
userId String | ||
} | ||
model Post extends Content { | ||
title String | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId String | ||
} | ||
model Image extends Content { | ||
url String | ||
} | ||
`; | ||
|
||
await expect(loadSchema(schema)).toResolveTruthy(); | ||
}); | ||
}); |