I am trying to figure out how I can model a many to many relationship in Prisma, using typescript.
I have models called User and Issue. Users can have many Issues and an issue can belong to many Users.
I am okay making the issue owned by one User, but I am trying to understand how to add an array (and what the identifers can be) when I make the issue have many users.
In my prisma schema I have:
model Issue {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String
description String
members User @relation(fields: [memberId], references: [id])
// If i try members User[] and repeat the above relation field, I get red underline in VS Code which suggests a problem memberId String @db.Uuid createdAt DateTime @default(now()) @db.Timestamptz(6) updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6) }
model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String @unique
password String
firstName String
lastName String
role Role @default(USER)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6)
issues Issue[]
}
How can I make the members record in the Issue model an array? How can I specify that each member id should be the user id?