Relation Filters
Filter records by their related models
Overview
Filter records by their relations using operators that depend on the relation’s cardinality — is/isNot for to-one relations, and some/every/none for to-many.
To-One Relations
For oneToOne and manyToOne relations:
| Operator | Description |
|---|---|
is |
Match related record |
isNot |
Exclude matching related record |
To-Many Relations
For oneToMany and manyToMany relations:
| Operator | Description |
|---|---|
some |
At least one match |
every |
All must match |
none |
No matches |
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 },
},
},
});