---
title: To-Many Relation Filters
description: Filter by collection relation slots using some, every, and none
icon: git-merge
---

## some

Match records where at least one related record matches:

```ts
// Users with at least one published post
const authors = await client.user.findMany({
  where: {
    posts: {
      some: { published: true },
    },
  },
});

// Posts with at least one approved comment
const posts = await client.post.findMany({
  where: {
    comments: {
      some: { approved: true },
    },
  },
});
```

## every

Match records where ALL related records match:

```ts
// Users where all posts are published
const consistentAuthors = await client.user.findMany({
  where: {
    posts: {
      every: { published: true },
    },
  },
});

// Posts where all comments are approved
const cleanPosts = await client.post.findMany({
  where: {
    comments: {
      every: { approved: true },
    },
  },
});
```

:::warning
`every` also matches records with NO related records. Use `some` + `every` to require at least one.
:::

```ts
// Users with at least one post, all published
const activeAuthors = await client.user.findMany({
  where: {
    AND: [
      { posts: { some: {} } },           // Has at least one
      { posts: { every: { published: true } } },  // All published
    ],
  },
});
```

## none

Match records where NO related records match:

```ts
// Users with no posts
const newUsers = await client.user.findMany({
  where: {
    posts: { none: {} },
  },
});

// Users with no banned posts
const cleanUsers = await client.user.findMany({
  where: {
    posts: {
      none: { status: "BANNED" },
    },
  },
});
```

## Many-to-Many Filtering

```ts
// Posts with "featured" tag
const featuredPosts = await client.post.findMany({
  where: {
    tags: {
      some: { name: "featured" },
    },
  },
});

// Posts with ALL specified tags
const tutorials = await client.post.findMany({
  where: {
    AND: [
      { tags: { some: { name: "tutorial" } } },
      { tags: { some: { name: "beginner" } } },
    ],
  },
});

// Posts without "draft" tag
const publishedPosts = await client.post.findMany({
  where: {
    tags: {
      none: { name: "draft" },
    },
  },
});
```

## Recursive filters

On a self relation, `recurse` makes `some`, `every` and `none` range over every
row the relation reaches transitively, not only the direct members: on
`children`, the descendants.

```ts
// Teams with Eve in them or in any team below them
const teams = await client.team.findMany({
  where: {
    children: {
      recurse: true,
      self: true,
      some: { members: { some: { userId: "eve" } } },
    },
  },
});
```

See [Recursive filters](/docs/client/filtering/relations#recursive-filters)
for `self`, `depth`, cycles and the provider rules.

## Nested Conditions

```ts
// Users with posts that have comments from admins
const mentionedUsers = await client.user.findMany({
  where: {
    posts: {
      some: {
        comments: {
          some: {
            author: {
              is: { role: "ADMIN" },
            },
          },
        },
      },
    },
  },
});
```

## Combined Filters

```ts
// Active users with engagement
const engagedUsers = await client.user.findMany({
  where: {
    active: true,
    OR: [
      { posts: { some: { views: { gt: 100 } } } },
      { comments: { some: {} } },
    ],
  },
});
```

## Examples

### Find Posts by Tag

```ts
async function getPostsByTags(tagNames: string[]) {
  return client.post.findMany({
    where: {
      AND: tagNames.map(name => ({
        tags: { some: { name } },
      })),
    },
    include: { tags: true },
  });
}
```


