Filippo Barcellos
03/04/2021, 10:54 PMmodel User {
id Int @id @default(autoincrement())
email String @unique
password String
username String
bio String?
image String?
posts Post[]
followedBy User[] @relation("UserFollows")
following User[] @relation("UserFollows")
}
I'm trying to update like this but is not working. I'm pretty sure I messed up somewhere
await prisma.user.update({
where: {
id: userLogged,
},
data: {
following: {
id: //user to be followed
},
},
});
Eddy Nguyen
03/04/2021, 10:56 PMconnect
object in the latest versions of Prisma:
https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-an-existing-record
await prisma.user.update({
where: {
id: userLogged,
},
data: {
following: {
connect: { id }
},
},
});
Eddy Nguyen
03/04/2021, 10:58 PMFilippo Barcellos
03/04/2021, 11:07 PMFilippo Barcellos
03/04/2021, 11:08 PMconnect
object but it doesn't find following as a argument in my schemaEddy Nguyen
03/04/2021, 11:19 PMEddy Nguyen
03/04/2021, 11:21 PMyarn prisma generate
and try running the query again
• Check that the user records exist
Otherwise, I’m out of ideas 😅 Hopefully someone else in the channel can help!Ryan
03/05/2021, 7:46 AMid
you’re passing to connect exists in the database?Filippo Barcellos
03/05/2021, 1:17 PMRyan
03/05/2021, 1:38 PMid
1, you can do the following:
await prisma.user.findMany({
where: { AND: [{ following: { none: { id: 1 } } }, { id: { not: 1 } }] },
})
Filippo Barcellos
03/05/2021, 3:53 PM