Secre
12/14/2021, 10:46 PMSecre
12/14/2021, 10:49 PMmodel Clan {
id Int @id @default(autoincrement())
owner String @unique
name String
level Int @default(1)
description String @default("[ Описание клана отсутствует! ]")
picture String @default("<https://i.imgur.com/OLSFcu5.gif>")
stars Int @default(0)
voiceTime Int @default(0)
monthActivityId Int? @unique
weeklyActivityId Int? @unique
monthActivity MonthActivity? @relation(fields: [monthActivityId], references: [id], onDelete: SetNull)
weeklyActivity WeeklyActivity? @relation(fields: [weeklyActivityId], references: [id], onDelete: SetNull)
user User[]
}
Activity models looks like:
model MonthActivity {
id Int @id @default(autoincrement())
messages Int @default(0)
voiceTime Int @default(0)
isClanActivity Boolean @default(false)
clan Clan?
user User?
}
as you can see, i setting null some fields if record about activity was deleted. And now i want to make same for clan. I mean, if i delete clan, i want to delete automatically activity records which binding for that clan by id.
How i can implement this by prisma schema, or i should handle it on my own?Jared Fraser
12/15/2021, 12:22 AMSecre
12/15/2021, 2:58 PMJared Fraser
12/15/2021, 11:17 PMmodel MonthActivity {
...
clan Clan? @relation(..., onDelete: Cascade)
}
Secre
12/16/2021, 12:20 PMJared Fraser
12/16/2021, 11:03 PMonDelete: SetNull
, so if you delete the activity the clan record will have a null value for the month activity relation