question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@map not carried over to `makeEnum`

See original GitHub issue

Given the following enum in schema.prisma

enum Role {
  ADMIN     @map("admin")

  @@map("role")
}

The generated JavaScript contains

exports.Role = makeEnum({
  ADMIN: 'ADMIN',
});

The value should be the same as inside the map

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Weakkycommented, Feb 9, 2021

Hey folks,

I think this issue stems from a misunderstanding of how @map works.

@map gives metadata to the Query Engine so that it knows the name of the model/enum field name stored in the database. @map never leaks into the client, it’s the field name that’s used in the client. eg:

Given this datamodel 👇,

model User {
  id Int @id @map("user_id")
  role Role  @map("user_role")
}

enum Role {
  ADMIN @map("admin")
}

The client should expose:

type User = {
  id: number
  role: Role
}

type Role = {
  ADMIN: 'ADMIN'
}

It’s only internally that the Query Engine will use these @map annotations to do the mappings. These @map values aren’t expected to be sent over the wire. They’re roughly used, for instance, to:

  • Select the proper columns. eg: SELECT user_id AS id, user_role AS role FROM ...
  • Compare against the actual enum values stored in the DB. eg: SELECT ... FROM ... WHERE user_role = "admin" 👈 "admin", not "ADMIN" here.

Hope that makes sense, I’m closing now. Feel free to ask further questions/re-open if you still think that’s wrong.

2reactions
pantharshit00commented, Feb 1, 2021

I can reproduce this with 2.16.0-dev.67. We should definitely export the correct value.

It works when you insert data as we use postgres/mysql enums under the hood.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Conveniently map between enum and int / String
No, it doesn't use ordinal. It relies on an explicitly defined int value. That int value is used as the map key (returned...
Read more >
Handbook - Enums - TypeScript
In this generated code, an enum is compiled into an object that stores both forward ( name -> value ) and reverse (...
Read more >
enum — Support for enumerations — Python 3.11.1 ...
An enumeration: is a set of symbolic names (members) bound to unique values. can be iterated over to return its canonical (i.e. non...
Read more >
A Guide to EnumMap - Baeldung
EnumMap is a Map implementation that exclusively takes Enum as its keys. In this tutorial, we'll discuss its properties, common use cases ...
Read more >
lloydmeta/enumeratum - Gitter
i'm guessing i should just write a matching function and not depend on ... because overriding that requires redefining the whole map (can't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found