-
Notifications
You must be signed in to change notification settings - Fork 86
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
nullish with id autoincrement #162
Comments
Seconded, I've ran into this issue multiple times already. I think by default the |
My solutionCurrently I am solving this issue by re-exporting the generated model and omitting fields I do not want to have there.
SuggestionsI think the best way how to solve would be adding excludeFields to the generator configuration.
Another way could be manually add some zod-omit annotation above the field itself in Prisma schema. Just starting with this problematic, might get to creating a PR later when I will know more pros and cons of possible solutions. |
We got the same issue. We use Zod + Prisma + tRPC + fastify, which requires the client to provide an id when creating a new record. So far we've solved it with following: export const connectorsRouter = router({
create: authedProcedure.input(UserModel.omit({id: true, updatedAt: true, createAt: true}))
.mutation(async (opts) => {
let server = opts.ctx.req.server;
return await server.prisma.user.create({
data: {
...opts.input, id: DbHelpers.getRandomArbitrary(100_000_000, 900_000_000) // generates random number
}
})
}), |
@vladaman thanks for your suggestion, this seems like a worthy solution! Would be really good to have some simple decorator option to make them nullish though. I'm going to +1 this thread :) |
Right now zod-prisma will generate zod file without nullish for ids that are auto incremented. We dont pass ids from client where its auto incremented, so it should be optional/nullish when generated.
May be you guys need following code fix in your types.ts
The text was updated successfully, but these errors were encountered: