diff --git a/packages/client/tests/functional/issues/21352-id-does-not-exist/_matrix.ts b/packages/client/tests/functional/issues/21352-id-does-not-exist/_matrix.ts new file mode 100644 index 000000000000..4f1f172b93f6 --- /dev/null +++ b/packages/client/tests/functional/issues/21352-id-does-not-exist/_matrix.ts @@ -0,0 +1,21 @@ +import { defineMatrix } from '../../_utils/defineMatrix' + +export default defineMatrix(() => [ + [ + { + provider: 'sqlite', + }, + { + provider: 'postgresql', + }, + { + provider: 'mysql', + }, + { + provider: 'cockroachdb', + }, + { + provider: 'sqlserver', + }, + ], +]) diff --git a/packages/client/tests/functional/issues/21352-id-does-not-exist/prisma/_schema.ts b/packages/client/tests/functional/issues/21352-id-does-not-exist/prisma/_schema.ts new file mode 100644 index 000000000000..ab58cb5b2e88 --- /dev/null +++ b/packages/client/tests/functional/issues/21352-id-does-not-exist/prisma/_schema.ts @@ -0,0 +1,37 @@ +import { foreignKeyForProvider, idForProvider } from '../../../_utils/idForProvider' +import testMatrix from '../_matrix' + +export default testMatrix.setupSchema(({ provider }) => { + return /* Prisma */ ` + generator client { + provider = "prisma-client-js" + } + + datasource db { + provider = "${provider}" + url = env("DATABASE_URI_${provider}") + } + + model User1 { + email ${idForProvider(provider)} + relation1 Relation1[] + } + + model Relation1 { + id ${idForProvider(provider)} + user User1 @relation(fields: [email], references: [email]) + email ${foreignKeyForProvider(provider)} + } + + model User2 { + id ${idForProvider(provider)} + relation2 Relation2[] + } + + model Relation2 { + field ${idForProvider(provider)} + user User2 @relation(fields: [email], references: [id]) + email ${foreignKeyForProvider(provider)} + } + ` +}) diff --git a/packages/client/tests/functional/issues/21352-id-does-not-exist/tests.ts b/packages/client/tests/functional/issues/21352-id-does-not-exist/tests.ts new file mode 100644 index 000000000000..d214317d2d5a --- /dev/null +++ b/packages/client/tests/functional/issues/21352-id-does-not-exist/tests.ts @@ -0,0 +1,45 @@ +import testMatrix from './_matrix' +// @ts-ignore +import type { PrismaClient } from './node_modules/@prisma/client' + +declare let prisma: PrismaClient + +testMatrix.setupTestSuite( + () => { + // TODO: this currently fails with "The column `j1.id` does not exist in the current database.". + // Close https://github.com/prisma/prisma/issues/21352 once fixed. + test('[1] should not fail', async () => { + await prisma.relation1.findMany({ + select: { + id: true, + }, + where: { + user: { + email: 'info@example.com', + }, + }, + }) + }) + + // TODO: this currently fails with "The column `j1.field` does not exist in the current database.". + // Close https://github.com/prisma/prisma/issues/21352 once fixed. + test('[2] should not fail', async () => { + await prisma.relation2.findMany({ + select: { + field: true, + }, + where: { + user: { + id: 'info@example.com', + }, + }, + }) + }) + }, + { + optOut: { + from: ['mongodb'], + reason: 'Only SQL databases were affected by regression #21352', + }, + }, +)