I'm building a simple feed where the user can see all the posts of the people he follows.
So in theory what I want to do is to get all posts (findMany) where the author of the posts is followed by the user who is requesting.
Sounds simple but I cannot find anything in the docs that explain how to do it.
Here is my schema:
User:
model User {
uid String @id @default(uuid())
username String? @db.VarChar(24) @unique
followers Follows[] @relation(name: "follower")
following Follows[] @relation(name: "following")
}
Post:
model Post {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
author User @relation(fields: [authorId], references: [uid])
authorId String
Follows (Explicit Many-To-Many)
model Follows {
follower User @relation(name: "follower", fields: [followerId], references: [uid])
followerId String
following User @relation(name: "following", fields: [followingId], references: [uid])
followingId String
Here is how I imagined it to work:
return prisma.post.findMany({
where: {
author: {
some: {
followers: {
followerId: {
equals: args.userId
}
}
}
}
},
include: {
author: {
include: {
followers: {
include: {
follower: true
}
}
}
}
}
})
The error I'm getting:
Unknown arg `some` in where.author.some
I also tried it without the "some" but then I'm getting the following output:
Unknown arg `followers` in where.author.followers