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

267
Views
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 answers
Answer question

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 Report
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!