Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

483
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda