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.
This PR aims to fix an error that occurs when enums are used as part of implicit many-to-many relations.
Reproducing
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.Fix
The provided fix augments the existing function
getJoinIdType
to look-up the corresponding field and uses both thetype
and thekind
in the generated join fields.