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

266
Visualizações
Prisma js ORM - how to filter for results that have entry in a related table (effectively JOIN)?

I have 2 tables:

model Collection {
    id                String                 @id @default(uuid()) @db.Uuid/
    floorPrices       CollectionFloorPrice[]
}

model CollectionFloorPrice {
    id           String     @id @default(uuid()) @db.Uuid
    collection   Collection @relation(fields: [collectionId], references: [id])
    collectionId String     @db.Uuid
}

How do I query collections that only have rows present in CollectionFloorPrice? In SQL it would be a simple JOIN.

This isn't working:

    return await this.prisma.collection.findMany({
      where: {
        floorPrices: {
          exists: true,
        },
      },
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Prisma's relation filters for a model named CollectionFloorPrice are:

export type CollectionFloorPriceFilter = {
  every?: CollectionFloorPriceWhereInput | null
  some?: CollectionFloorPriceWhereInput | null
  none?: CollectionFloorPriceWhereInput | null
}

To get only Collections that have at least one CollectionFloorPrice, you should use some (instead of exists) and specify a condition that always return true for any related record that exists.

And if you want to your query includes related CollectionFloorPrices you must specify it in include property.

 return await this.prisma.collection.findMany({
   where: {
     floorPrices: {
       some: {
         id: { not: "" } // It always should be true.
       },
     },
   },
   
   // if you want to include related floor prices in returned object:
   include: {
     floorPrices: true,
   },
 });
about 4 years ago · Juan Pablo Isaza Relatório
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