-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
WhereUniqueInputSchema validation behaviour #68
Comments
@binary-birthday Since the generator just takes the information that is present in the model User {
id String @id @default(cuid())
email String @unique
//...rest
} // Type in prisma index.d.ts
export type UserWhereUniqueInput = {
id?: string
email?: string
}
// created schema
export const UserWhereUniqueInputSchema: z.ZodType<Prisma.UserWhereUniqueInput> =
z
.object({
id: z.string().optional(),
email: z.string().optional(),
})
.strict();
export default UserWhereUniqueInputSchema;
So I think currenly you need to check if the fields are undefined before hitting the schema. Another way could be to add a custom refine to the // I'm sure this check can be refined a bit :)
UserWhereUniqueInputSchema.refine((data) => {
return Object.entries(data).some(([_key, value]) => {
return value !== undefined;
});
}); This is something that could also be generated automatically by the generator, since all the information should be there, but I would suggest one of the manual options from above until I can look into this in more detail. |
I couldn't get it off my mind so I implemented it straight away. Should work now in the latest version as you described it |
Oh awesome. I'll check it out now. For a workaround I thinking about using:
But this will be much better. |
closing since it's now implemented |
@chrishoermann I've encountered an issue with this feature: when I apologise for not recognising this earlier. |
Thanks for pointing this out and no problem @binary-birthday. I'll revert back to the previous implementation in the next release. |
I have a User model with two unique fields, id and phoneNumber.
When validating the input using the UserWhereUniqueInputSchema, validation succeeds in the scenario where:
I would expect that validating using the WhereUniqueInputSchema should only succeed if at least one of the required unique fields is a valid input.
The text was updated successfully, but these errors were encountered: