-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It's not possible to omit relation field #110
Comments
@oceandrama thanks for the hint. I need to look into this in more detail but I think it is because the omitted fields are currently only propagated to the "normal" |
Glad I found this issue, was messing up my use case. Will leave some info incase it helps. Relevant model from my schema: model Task {
id String @id @default(auto()) @map("_id") @db.ObjectId
completed Boolean @default(false)
title String /// @zod.string.min(1)
size TaskSize @default(MEDIUM)
description String?
number Int /// @zod.custom.omit(["model", "input"])
start DateTime? // Date at which this task can be worked on
end DateTime? // Day this task is due
url String? // Page that triggered this task to be created
User User @relation(fields: [userEmail], references: [email])
userEmail String @unique
} I am validating my input using the generated I suppose my solution will be to use the base unchecked input type, and simply omit both the user and number types from the input. Would be nice to get support added for the omits on the non-base input versions at some point in the future, or at least update the README to make that clearer. EDIT: Yep, worked like a charm. As per the OP though, I think you have to stick to the unchecked schema variants for it to work properly. |
Just thought I'd bump this as well, running into a simlar issue. model JobApplication {
id String @id @default(cuid())
cover_letter String
job_post JobPost @relation(fields: [job_post_id], references: [id], onDelete: Cascade)
job_post_id String
applicant Profile @relation(fields: [applicant_id], references: [id], onDelete: Cascade)
applicant_id String /// @zod.custom.omit([input])
@@index([job_post_id])
@@index([applicant_id])
} Using the unchcked inputs isn't too practical in my example const application = await ctx.prisma.jobApplication.create({
data: {
...input,
job_post_id: undefined,
applicant: {
connect: {
id: ctx.session.user.profile_id,
},
},
job_post: {
connect: {
id: input.job_post_id,
},
},
},
}); Ideally would love to be able to go ...
applicant Profile @relation(fields: [applicant_id], references: [id], onDelete: Cascade) /// @zod.custom.omit([input])
... const application = await ctx.prisma.jobApplication.create({
data: {
...input,
applicant: {
connect: {
id: ctx.session.user.profile_id,
},
},
},
});``` |
With this schema:
it generates
You can add
omit
toauthorId
to get this
It's still possible to create article with author using
author: { connect: { id } }
instead ofauthorId
And if you try to add
omit
toauthor
tooyou recieve an error:
The text was updated successfully, but these errors were encountered: