Are deeply nested where clauses supported
Given the following example query:
each item in the where clause is a related table of the previous item (A table related to B table related to C table etc. )
Should this work and my syntax is just wrong or is this not supported?
3 Replies
You chose to compile with the bot. One moment while I piece together your answer…
Deeply nested where clauses are supported in Prisma, but the syntax must follow Prisma's relation filter conventions. For each relation, you need to use the correct filter operator (
some
, is
, etc.) depending on whether the relation is one-to-many or one-to-one.
For your example, if the relations are as follows:
- A has many B (B: { some: ... }
)
- B has a one-to-one or many-to-one relation to C (C: { is: ... }
)
- C has a one-to-one or many-to-one relation to D (D: { is: ... }
)
- D has a field X
Then your syntax is generally correct. Prisma supports chaining relation filters like this, and you can nest them as deeply as your schema allows. Here’s a simplified example from the documentation:
This demonstrates filtering through multiple levels of relations using some
and is
as appropriate for the relation type. For one-to-one or many-to-one, use is
; for one-to-many, use some
/every
/none
as needed. If you get an error, double-check your schema to ensure you’re using the correct filter for each relation type and that the relation names match your Prisma schema.
For more details and examples, see the official documentation on relation filters and filtering on relations.
If you encounter a specific error, it may be due to a mismatch in relation types or incorrect use of filter operators, not a lack of support for deep nesting itself PRISMA - 'where' with deeply nested relation.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.I figured it out, I needed to filter on the nested select's too to get the result I was looking for
I am glad to hear that you were able to figure it out!