where's the best way to run a where on a deeply re...
# orm-help
j
where's the best way to run a where on a deeply related query? Say if I have the relations A -> B -> C -> D. And I want to return A wth all relations of B, with all relations of C with a relation of D that
type=item
SQL i'm trying to mimic
Copy code
SELECT *
FROM a
LEFT JOIN b
LEFT JOIN c
LEFT JOIN d
WHERE d.type='item'
Copy code
this.prisma.A.findMany({
  include: {
    B: {
      include: {
        C: {
          include: {
            d: {
              where: {
                type: 'item'
              }
            }
          }
        }
      }
    }
  }
})
r
In your schema, is it a 1-many relation b/w all of them?
j
Is that the reason why sometimes I can use where and sometime I cannot?
based on the relationship type?
r
You can always use where. But depending on the relationship what's inside where changes
It would be great if you could share nhe above schema so that I can send you the exact query