Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
1 reply
Styly

Prisma Two of the same model inside of a model

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  relationMode = "prisma"
}

model wallet {
  id        String        @id @unique
  balance   Decimal       @default(0) @db.Decimal(65, 12)
  uuidProof String        @default(uuid())
  history   transaction[] @relation(name: "senderReceiver")
  @@index([id])
}

model transaction {
  id          String    @id @unique
  sender      wallet    @relation("sender",fields: [senderId], references: [id])
  senderId    String @unique
  receiver    wallet    @relation("receiver",fields: [receiverId], references: [id],onDelete: Cascade)
  receiverId  String @unique
  transferedAt DateTime  @default(now())
  @@index([senderId, receiverId])
}
This is what i came up with the issue is that i need to use to instances of wallet with different names.
Was this page helpful?