Hi all, I have an enum in my prisma schema like th...
# orm-help
m
Hi all, I have an enum in my prisma schema like the below:
Copy code
enum paddock_slope_enum {
  One__0____7__ @map("One (0° - 7°)")
  Two__8____15__ @map("Two (8° - 15°)")
  Three__16____25__ @map("Three (16° - 25°)")
  Four___26__ @map("Four (>26°)")
}
The generated enum becomes:
Copy code
export const paddock_slope_enum: {
  One__0____7__: 'One__0____7__',
  Two__8____15__: 'Two__8____15__',
  Three__16____25__: 'Three__16____25__,
  Steep_Hill___26__: 'Steep_Hill___26__'
};
This is unexpected for me as I would have expected the values of the enum keys to be the map values in the schema? So my findMany GET API is returning the values with all the underscores - why is that? And can I get around it to get the value of the map?
r
@Moh 👋 Prisma will always return the values defined in the schema and not what you specified in
@map
. Map is just the name that you want to store in the database. If you need the database value, then you have to go for a raw query.
👍 1
m
Thanks for the clarification @Ryan - are there any reasons for this? The generated enum seems to become a little useless then, unless I'm missing a use-case for the current set-up?
r
You would always use the generated enum with PrismaClient as that would be then converted to the enum you mentioned in
@map
at the database level.