Prisma, update scalarList/array
I´m doing an Spotify clone and I´m trying to add a song to a playlist but my query doesn't work, to finish this clone only need to add a song to a playlist and delete a song from a playlist, until this point, everything was good following the documentation on prisma docs, but I cannot do this query, every time get an error, so if someone can tell how can I do this with an example, I'll be very grateful.
This is my first question here so don't kill me and thanks!
My schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String @unique
firstName String
lastName String
password String
playlists Playlist[]
}
// add a Song to a playlist, here?
model Song {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
artist Artist @relation(fields: [artistId], references: [id])
artistId Int
playlists Playlist[]
duration Int
url String
}
model Artist {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
songs Song[]
name String @unique
}
// or here? or both?
model Playlist {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
songs Song[]
user User @relation(fields: [userId], references: [id])
userId Int
}
And here is my query:
lists = await prisma.song.findFirst({
select: {
playlists: true
},
where: {
id: +songId
}
})
const list = await prisma.playlist.findUnique({
where: {
id: playlistId
}
})
lists = [ ...lists.playlists, list ]
await prisma.song.update({
where: { id: +songId },
data:{
playlists: lists
}
})
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum