Detect parents with no related records
Find users whose posts collection is empty.
Prisma · Const
none is a Prisma Client relation filter for to-many relations. It selects parent records with no related records matching the nested filter.
In a Prisma Client relation filter, none selects parent records for which a to-many relation has no related records matching the nested filter. An empty object tests for complete absence; adding conditions restricts the absence test to related records that satisfy those conditions.
relation: { none: {} }| Name | Type | Description |
|---|---|---|
none | RelationFilter | Nested relation filter object; {} checks that no related records exist, while nested conditions limit which related records are considered. |
A Prisma Client query result containing parent records for which no related to-many records satisfy the nested filter.
none to filter parent records based on the absence of matching records in a to-many relation.none filter selects users whose related collection contains no posts.none applies to to-many relation filters; it is not the operator for checking a missing to-one relation.none.const usersWithZeroPosts = await prisma.user.findMany({
where: {
posts: {
none: {},
},
},
include: { posts: true },
});Returns users whose posts relation contains zero records.
Find users whose posts collection is empty.
Exclude parents that have related records satisfying a predicate.
none mean in a Prisma relation filter?none is a Prisma Client relation filter for to-many relations. It returns parent records with zero related records that satisfy the nested condition; none: {} therefore finds parents with no related records.
Follow-up: How would you find parents with no related records matching a condition? Use none with that condition inside the relation filter, for example posts: { none: { published: true } }.
none: {}?An empty filter object means that no records in the to-many relation may exist. The relation can also contain a nested filter when absence should be evaluated only against matching related records.
Follow-up: How do you express the absence of a to-one relation? Use the documented null-check relation filter instead of a to-many none filter.
none placed in a Prisma Client query?The documented use case is querying users whose posts relation has zero posts. Prisma places none inside where, under the relation field, and the query can still include the relation in its returned data.
Follow-up: Can the query both filter and load the relation? Yes; relation filtering in where and relation loading through include are separate parts of the query.
someeveryRelation querieswhereinclude