Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for including count of relational fields #26

Open
Tracked by #116
RobertCraigie opened this issue Jun 21, 2021 · 0 comments
Open
Tracked by #116

Add support for including count of relational fields #26

RobertCraigie opened this issue Jun 21, 2021 · 0 comments
Labels
Projects

Comments

@RobertCraigie
Copy link
Owner

RobertCraigie commented Jun 21, 2021

Problem

Prisma supports including the count of a relational field, so we should too.

const users = await prisma.user.findMany({
  include: {
    _count: {
      select: { posts: true },
    },
  },
})

which returns an object like this

{
  id: 1,
  email: 'alice@prisma.io',
  name: 'Alice',
  _count: { posts: 2 }
}

Prisma also have support for filtering by the count of the relation, see https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#filter-the-relation-count

@RobertCraigie RobertCraigie added the kind/feature A request for a new feature. label Jun 21, 2021
@RobertCraigie RobertCraigie added this to To do in v1.0.0 via automation Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
v1.0.0
To do
Development

No branches or pull requests

1 participant