I'm creating a system where every user has some role. After that, each role contains a list of permissions that drive logic in the application.
Prisma schema (prisma version 4.1.1)
For that purpose I created this Prisma schema:
model Role {
id String @id @default(cuid())
name String @db.VarChar(255)
permissions PermissionOnRoles[]
users User[]
}
model Permission {
id String @id
name String @db.VarChar(255)
description String @db.VarChar(255)
roles PermissionOnRoles[]
}
model PermissionOnRoles {
role Role @relation(fields: [roleId], references: [id]) @ignore
roleId String
permission Permission @relation(fields: [permissionId], references: [id])
permissionId String
assignedAt DateTime @default(now()) @ignore
assignedBy String @ignore
@@id([roleId, permissionId])
}
How DB looks like now:
After I migrate this schema I added some DEV data to database and real table looks like this:
Role:
PermissionOnRoles
Permission

But when I try to query the role included permission with queries like:
await prisma.role.findMany({
include: {
permissions: true,
},
});
Error:
Invalid `prisma.role.findMany()` invocation:
{
include: {
permissions: true,
~~~~~~~~~~~
? users?: true,
? _count?: true
}
}
Unknown field `permissions` for include statement on model Role. Available options are listed in green. Did you mean `users`?
I basically get the same error if I try to open the Role table in Prisma Studio.
I'm not great at designing databases so the design of my database could be wrong, or maybe I just miss something really stupid but I am not able to find anything so I am up for any advice which can lead me to the right way.
What I tried:
- delete node modules
- update prisma & @prisma/client to latest version
- prisma migrate dev - to verify whatthe is in schema is in table
- prisma generate - just to test everything.