kraustifer
kraustifer
DTDrizzle Team
Created by kraustifer on 8/15/2023 in #help
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 },
},
},
});
}
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?
5 replies