PrismaP
Prisma2y ago
5 replies
Mattéo

Multiple relation between models

Hello guys, I'm creating a marketplace but I have a problem. I have 2 models:
User
and Post. I want the user to have the fields posts (his own posts) and favoritePosts (the posts he liked).

I made this but it doesn't work:

model User {
  id               String   @id @default(cuid())
  firstName        String
  lastName         String
  email            String   @unique
  phone            String   @unique
  password         String
  verificationCode String?
  posts            Post[]
  favoritePosts    Post[]
  createdAt        DateTime @default(now())
  updatedAt        DateTime @default(now()) @updatedAt
}

model Post {
  id          String   @id @default(cuid())
  slug        String
  title       String
  description String
  price       Int
  images      String[]
  reports     Report[]
  userId      String
  user        User     @relation(fields: [userId], references: [id])
  createdAt   DateTime @default(now())
  updatedAt   DateTime @default(now()) @updatedAt
}


Can you help me please ?
Was this page helpful?