1

I am trying to only return items from our DB, if the children within an include exists.

I am using Prisma to query our postgres DB. Previously, using sequelize, you could add a required:true to the include, meaning only items that had this include would be returned. However, I can not seem to do this with Prisma, so its returning many more items that I don't need.

Here is the structure that i have:

 where: {
      ...parameters_.where,
    },
    include: {
      Products: {
        where: {
          active: true,
          ParentId: parameters_.ParentId,
        },
      }
    }

So I only want to return the top level, if Products actually exists. (This will return an array, and currently it returns if the Products array is empty as well as when its not).

As mentioned, with sequelize it was possible to do the following:

      include: [
        {
            model: ModelName,
            as: "modelName",
            required: true
       },
      ]    
Sai Gummaluri
  • 1,340
  • 9
  • 16
Jm3s
  • 556
  • 2
  • 12
  • 24
  • 1
    What you need to do is figure out how to tell Prisma to do a `LEFT JOIN`. That's what the Sequelize equivalent does. – Pointy Mar 01 '22 at 13:57
  • See [this question](https://stackoverflow.com/questions/68761366/left-joins-and-aggregation-in-a-single-prisma-query) – Pointy Mar 01 '22 at 14:01

0 Answers0