Ridhwaan Shakeel
10/03/2021, 9:03 PMconst album = {
...result,
songs: {
connectOrCreate: result.songs.map(s => ({
create: {
...s,
artists: {
connectOrCreate: s.artists.map(a => ({
create: a,
where: { spotify_id: a.spotify_id }
}))
},
where: { spotify_id: s.spotify_id }
}))
}
}
schema:
model Album {
artists Artist[]
songs Song[]
}
model Artist {
albums Album[]
songs Song[]
}
model Song {
album Album @relation(fields: [album_spotify_id], references: [spotify_id], onDelete: Cascade)
artists Artist[]
}
Ryan
10/04/2021, 5:28 AM