Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

478
Views
Prisma - How to query by relation? (Get posts of followed users)

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
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!