Skip to content

[Feature Request] Field-level validation for enums #2034

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

Open
aladinelkhalil opened this issue Mar 9, 2025 · 0 comments
Open

[Feature Request] Field-level validation for enums #2034

aladinelkhalil opened this issue Mar 9, 2025 · 0 comments

Comments

@aladinelkhalil
Copy link

I want to able to customize enum field validation message (for zod schema generation in my case) in a cleaner way. Currently the only workaround is converting the enum to a string value and using model level validation with the in operator as such

model User
{ 
... 
role        String

@@validate(role in ['ADMIN', 'USER'], 'you have to select a role')
}

I'm suggesting support for field level validation for enums just the same as for strings and numbers @Length(...), @min(...) etc, such as:

enum Role {
    ADMIN
    USER
}

model User
{ 
... 
role        Role @validate(message: "you have to select a role")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant