1

This is my quite simple Prisma 3 schema for a dashboard application

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id         String     @id @default(uuid())
  projects   Project[]
  owner      Project[]  @relation("owner")
  likes      Project[]  @relation("likes")
}

model Project {
  id         String     @id @default(uuid())
  users      User[]
  owner      User       @relation("owner", fields: [ownerId], references: [id])
  ownerId    String
  likes      User[]     @relation("likes", fields: [likesId], references: [id])
  likesId    String
}

It works as expected but I'm interested if I could make it more concise
In order to track owner and likes to Project model, I had to add:

  1. Relations description
  2. Redundant service fields ownerId and likesId for disambiguation
  3. Redundant service fields owner and likes to User model

Is it possible to make it a little bit less verbose?
What if I would need to add 3-4 additional relation fields?

Igniter
  • 857
  • 9
  • 24
  • It's not possible to reduce the verbosity and the schema you have is the recommended way to do it according to the [relations article](https://www.prisma.io/docs/concepts/components/prisma-schema/relations#disambiguating-relations) in the Prisma docs. If you feel that the current syntax is confusing or too verbose and can be improved in any way, please do feel free to make an issue about it in the [prisma github repo](https://github.com/prisma/prisma). – Tasin Ishmam Sep 21 '21 at 11:04

0 Answers0