Drizzle TeamDT
Drizzle Team3y ago
4 replies
kraustifer

Count of one-to-many relation in query

Migrating from Prisma - I had something like the following:

export async function getAllOrganizations() {
  return db.organization.findMany({
    include: {
      _count: {
        select: { individuals: true },
      },
    },
  });
}


This effectively fetched a count of all the individuals underneath an organization (a one-to-many relationship).

How can I do something similar in Drizzle? I took a look at passing in extras to the query, but it noted that aggregations weren't a possibility in extras currently. Am I missing something?
Was this page helpful?