Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

484
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda