Relation Filters
Filter records by their related models
Overview
Filter records by their relations using operators that depend on cardinality:
is/isNot for to-one relations, and some/every/none for to-many.
Direct polymorphic filters first select a target type; polymorphic inverses
use their declared to-one or to-many cardinality.
To-One Relations
For singular slots (s.toOne):
| Operator | Description |
|---|---|
is |
Match related record |
isNot |
Exclude matching related record |
To-Many Relations
For collection slots (s.toMany):
| Operator | Description |
|---|---|
some |
At least one match |
every |
All must match |
none |
No matches |
Polymorphic Relations
A direct polymorphic relation combines one public target discriminator with a
target-specific is or isNot filter. Optional direct storage also supports
bare null, { is: null }, and { isNot: null }. An inverse polymorphic
relation uses the ordinary operator family for its declared cardinality. See
Polymorphic Relations.
Quick Examples
// Users with admin profile
await client.user.findMany({
where: {
profile: {
is: { role: "ADMIN" },
},
},
});
// Users with at least one published post
await client.user.findMany({
where: {
posts: {
some: { published: true },
},
},
});
// Posts with all approved comments
await client.post.findMany({
where: {
comments: {
every: { approved: true },
},
},
});