Filter by a related author's fields
Exclude posts authored by a specific user.
Prisma · Const
isNot excludes records whose related to-one record matches the supplied nested filter. It is used inside Prisma Client where clauses, such as filtering posts whose author is not named Bob.
Use isNot inside a Prisma Client where filter to exclude records whose related one-to-one record matches the supplied criteria. The nested object describes the related record that must not match; for example, isNot: { name: "Bob" } excludes posts authored by Bob.
relation: { isNot: { field: value } }| Name | Type | Description |
|---|---|---|
filter | object | Nested filter object describing the related record that must not match. |
A Prisma Client query result containing parent records whose related record does not match the nested filter.
isNot is a Prisma Client option for filtering through a related record.isNot for to-one relations; it is not the relation-list filter for to-many relations.const posts = await prisma.post.findMany({
where: {
author: {
isNot: { name: "Bob" },
},
},
});Returns posts whose related author does not have the name Bob.
Exclude posts authored by a specific user.
Select parent records whose to-one relation does not satisfy a set of conditions.
isNot do in a Prisma where clause?isNot is a Prisma Client relation filter for excluding records whose related record matches nested criteria. For example, author: { isNot: { name: "Bob" } } returns posts whose author is not Bob.
Follow-up: How would you filter a relation-list instead? Use the list-relation filters documented for to-many relations, rather than the to-one isNot option.
isNot interpreted?Place isNot under a to-one relation field and provide the related record's field conditions as its value. Prisma returns parent records for which the related record does not satisfy those conditions.
Follow-up: What if the requirement is to exclude several different author conditions? Combine relation filters with Prisma's logical operators such as NOT, AND, or OR as appropriate.
isNot query.A typical query is prisma.post.findMany({ where: { author: { isNot: { name: "Bob" } } } }). It filters posts according to properties of the related author and excludes matching authors.
Follow-up: Can isNot be used with composite types? Yes; Prisma's reference also documents it for composite fields, where it excludes composites that match the supplied object.
isNOTANDOR