Skip to content
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

Handle enum primary keys on many-to-many relationships #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frannyfx
Copy link

This PR aims to fix an error that occurs when enums are used as part of implicit many-to-many relations.

Reproducing

enum RoleType {
  User
  Admin
}

model Role {
  roleId      RoleType     @id
  permissions Permission[]
}

model Permission {
  permissionId String @id
  roles        Role[]
}
yarn prisma generate

Cause

The generator for many-to-many implicit relationships presumes the fields involved in these relations are scalars, but they can also be enums too. The pre-supposition that the field is a scalar means that enums are not considered, and when converting from a Prisma type to a database type in generateFieldType, it is unable to find a mapping between the two.

Error:
Unsupported type RoleType for database postgresql

Fix

The provided fix augments the existing function getJoinIdType to look-up the corresponding field and uses both the type and the kind in the generated join fields.

@frannyfx frannyfx requested a review from valtyr as a code owner May 14, 2024 09:31
@valtyr
Copy link
Owner

valtyr commented May 21, 2024

Awesome, thanks for your contribution! Please add a changeset (yarn changeset) and I'll merge this :)

@arthurfiorette
Copy link

@valtyr any blockers on this?

@WKampel
Copy link

WKampel commented Oct 27, 2024

Can we get this merged?

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

Successfully merging this pull request may close these issues.

4 participants