Hello all I have a schema as model Business { ...
# orm-help
m
Hello all I have a schema as model Business { id String @id @default(uuid()) name String } model Role { id String @id @default(uuid()) name String business Business? @relation(fields: [business_id], references: [id]) business_id String? @@unique([business_id, name]) @@map("role") } I have a scenario to add roles with business OR without business. How this can be achieved with upsert. I have tried to run below query, but it returns error. error screenshot attached as well await prisma.role.upsert({ where: { business_id_name: { business_id: null, name: 'Owner' } }, update: {}, create: { business_id: null, name: 'Owner', }, });
r
Roles can be managed as bitwise (it's a very common and good practice)
so in the prisma schema it can just be mapped to an Int
it would make your design a lot better and your code much simpler. (when it comes to doing user role checks and user role updates)
m
I have another table as permission. permissions are assigned to roles. and single role can links with one business or with no business. if role is not linked with any business then it means it is linked with all business those are created in this system