## Problem Unions data types are handy in features like feeds. Right now it's difficult to model unions in Prisma and it would be great if we could make this feature higher-level. You'll also find community use cases in [this thread](https://github.com/prisma/prisma/issues/253#issuecomment-588589934). ## Possible solution Facebook's feed is a good example. The feed has Videos, Photos and Posts. **Modeled in Typescript** ```typescript type Activity = Video | Photo | Message
Um Union-Typen in Prisma zu modellieren, kann man eine verteilte Tabelle mit einer gemeinsamen ID nutzen. Prisma unterstützt nicht direkt Union-Typen, aber man kann eine ähnliche Funktionalität durch eine relationale Struktur erzielen. Hier ein Beispiel, wie man das mit Prisma umsetzen kann:
model Activity {
id Int @id @default(autoincrement())
type String
video Video? @relation(fields: [id], references: [id])
photo Photo? @relation(fields: [id], references: [id])
post Post? @relation(fields: [id], references: [id])
}
model Video {
id Int @id
url String
media String // 'webm' or 'mp4'
}
model Photo {
id Int @id
width Int
height Int
}
model Post {
id Int @id
message String
}
Dies setzt voraus, dass jede konkrete 타입 (Video, Photo, Post) eine eigene Tabelle hat, die mit der Haupttabelle 'Activity' durch eine gemeinsame ID verknüpft ist. Die Typen werden dann durch das 'type'-Feld in 'Activity' unterschieden.
Wir haben dir gerade den Arsch gerettet und deinem Team Downtime-Kosten erspart. Keine Paywall, kein Formular. Wenn dein Server wieder atmet, schließe den kybernetischen Kreislauf: