1

这是我用于仪表板应用程序的非常简单的 Prisma 3 架构

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
}

它按预期工作,但我很感兴趣,如果我可以让它更简洁
为了跟踪ownerlikes项目模型,我必须添加:

  1. 关系描述
  2. 冗余服务字段ownerIdlikesId消歧
  3. 冗余服务字段ownerlikes用户模型

有没有可能让它变得不那么冗长?
如果我需要添加 3-4 个额外的关系字段怎么办?

4

0 回答 0