Utsuhoagie
Explore posts from serversTTCTheo's Typesafe Cult
•Created by Utsuhoagie on 7/10/2023 in #questions
Create-if-not-exists multiple explicit many-to-many relations
(note: I'm new to using Prisma and unfamiliar with the syntax)
I have
Playlist
and Video
models, with an explicit many-to-many relationship (to hold extra data). Say I have an array of Video
primary keys, how do I add these videos to a playlist, if they aren't already in it?
My closest working example is this. To my understanding, upsert
is actually an "create-if-not-exists, otherwise update" operation, but with an empty object for update
thus working similarly to what I want (albeit slightly more complicated). However, here I am only adding 1 video to the playlist at once. Is there a way to add multiple videos (aka creating multiple many-to-many relations to the join table between Playlist
& Video
), ideally in one query?
2 replies