https://github.com/samchon/prisma-bug-undefined-join-bug
https://github.com/samchon/prisma-bug-undefined-join-bug
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/samchon/prisma-bug-undefined-join-bug
- Owner: samchon
- License: mit
- Created: 2023-05-26T04:35:56.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-26T05:21:14.000Z (about 3 years ago)
- Last Synced: 2025-02-25T04:34:20.179Z (over 1 year ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Error reproducing repo for Prisma.
When `undefined` value be assigned in `include` option, `Prisma` can't distinguish the `undefined` value, and just perform join operation. Therefore, when conditional join is required, manual `delete` operation be required, and it seems inconvenient and ridiculous.
```typescript
const read = (prisma: PrismaClient) =>
(joinFiles: boolean) =>
async (id: string) => {
const article = await prisma.bbs_articles.findFirstOrThrow({
where: { id },
include: {
files: joinFiles
? { include: { file: {} } }
: undefined,
},
});
console.log({
joinFiles,
expectedBehavior: joinFiles === !!article.files?.length,
files: article.files,
});
};
read(prisma)(false)("some-bbs-article-id");
```
> ```bash
> {
> joinFiles: false,
> expectedBehavior: false,
> files: [
> {
> id: '608b855c-8728-479c-8105-2594052c84c1',
> bbs_article_id: 'f1f89022-d872-4bb4-b429-cace6b2f153a',
> attachment_file_id: 'd6779072-24a2-4424-bc56-4db501671202',
> sequence: 0
> }
> ]
> }
> ```