You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose you have an m-to-n relation: OrganizationRole <- OrganizationRolePrivilege -> Privilege. The Organization role is a delegate further breaking down into 2 concrete models: SystemDefinedRole and CustomOrganizationRole:
model OrganizationRole {
id Int @id @default(autoincrement())
name String
rolePrivileges OrganizationRolePrivilege[]
type String
@@delegate(type)
}
// roles common to all orgs, defined once
model SystemDefinedRole extends OrganizationRole {
name String @unique
}
// roles specifc to each org
model CustomOrganizationRole extends OrganizationRole {
name String
organizationId Int
organization Organization @relation(fields: [organizationId], references: [id])
@@unique([organizationId, name])
@@index([organizationId])
}
model OrganizationRolePrivilege {
organizationRoleId Int
privilegeId Int
organizationRole OrganizationRole @relation(fields: [organizationRoleId], references: [id])
privilege Privilege @relation(fields: [privilegeId], references: [id])
@@id([organizationRoleId, privilegeId])
}
model Privilege {
id Int @id @default(autoincrement())
name String // e.g. "org:manage"
orgRolePrivileges OrganizationRolePrivilege[]
@@unique([name])
}
With the Privilege table is already preloaded with all privileges, it's not possible to create a new concrete Role and connect it to existing privileges.
Below are a few attempts but unsuccessful:
Attempt 1: Connecting by foreign key
awaitdb.systemDefinedRole.create({data: {name: 'Admin',rolePrivileges: {create: [{privilegeId: 1,// ✖ currently requires a organizationRoleId but organizationRole not created yetorganizationRoleId:1}],},},});
Description and expected behavior
Suppose you have an m-to-n relation:
OrganizationRole
<-OrganizationRolePrivilege
->Privilege
. The Organization role is a delegate further breaking down into 2 concrete models:SystemDefinedRole
andCustomOrganizationRole
:With the
Privilege
table is already preloaded with all privileges, it's not possible to create a new concrete Role and connect it to existing privileges.Below are a few attempts but unsuccessful:
Attempt 1: Connecting by foreign key
Attempt 2: Connecting by a relation name
Environment (please complete the following information):
Additional context
See related Discord thread.
With raw Prisma, this is achievable in 2 different ways. Both of which expose the
privilege
relation to connect to:The text was updated successfully, but these errors were encountered: