prisma-kysely
prisma-kysely copied to clipboard
Handle enum primary keys on many-to-many relationships
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.
Awesome, thanks for your contribution! Please add a changeset (yarn changeset
) and I'll merge this :)
@valtyr any blockers on this?
Can we get this merged?