Closed iksemot closed 11 months ago
And this one too!
I have a similar issue (if not the same), but just in case it can help :
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id String @id @default(autoincrement())
name String
createdPosts Post[] @relation("CreatedPosts")
@@allow('all', true)
}
model Post {
id Int @id @default(autoincrement())
title String
createdBy String?
creator User? @relation("CreatedPosts", fields: [createdBy], references: [id], onDelete: Cascade)
@@allow('all', true)
}
Following code:
const prisma = enhance(new PrismaClient(), {})
const post = await prisma.post.create({
data: {
title: 'Title',
creator: {
connect: {
id: undefined,
},
},
}
})
Errors with:
Uncaught (in promise) TRPCClientError:
Invalid `this.prisma[this.model].create()` invocation in
/Users/augustin/Documents/Dev/Perso/schools/node_modules/@zenstackhq/runtime/enhancements/proxy.js:64:53
61 create(args) {
62 return __awaiter(this, void 0, void 0, function* () {
63 args = yield this.preprocessArgs('create', args);
→ 64 const r = yield this.prisma[this.model].create({
data: {
title: "",
creator: {
connect: {
id: undefined,
? email?: String,
? AND?: UserWhereInput | UserWhereInput[],
? OR?: UserWhereInput[],
? NOT?: UserWhereInput | UserWhereInput[],
? name?: StringFilter | String,
? createdPosts?: PostListRelationFilter,
}
}
},
select: {
id: true
}
})
Argument `connect` of type UserWhereUniqueInput needs at least one of `id` or `email` arguments. Available options are marked with ?.
at TRPCClientError.from (transformResult-6fb67924.mjs:4:1)
at eval (httpBatchLink.mjs:190:40)
Got it @Azzerty23 . Thanks! Working on a fix now 😄
Fixed in v1.1.1
Description and expected behavior
Method create errors because of
undefined
as the value of relation.The workaround is to use
{}
butundefined
is valid and allowed in pure PrismaClient.Environment (please complete the following information):
Additional context
Given data model:
Following code:
Errors with: