© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
36 replies
jakeleventhal

How to get the count of relations?

const products = await db.query.masterProducts.findMany({
  limit: pageSize,
  offset: page * pageSize,
  where: whereFilter
});
const products = await db.query.masterProducts.findMany({
  limit: pageSize,
  offset: page * pageSize,
  where: whereFilter
});

I have another table
inventoryItems
inventoryItems
and there is a one-to-many relationship where one
masterProduct
masterProduct
can have many
inventoryItems
inventoryItems
and one
inventoryItem
inventoryItem
is linked to one and only one
masterProduct
masterProduct
on the
masterProductId
masterProductId
field.

How can I include a count of
inventoryItems
inventoryItems
in this query? I just want a
number
number
of how many
inventoryItems
inventoryItems
have the
masterProductId
masterProductId
field matching the
id
id
field for each row in the
masterProducts
masterProducts
query
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Include count of relations
Drizzle TeamDTDrizzle Team / help
3y ago
How to get the return Type of a query with relations?
Drizzle TeamDTDrizzle Team / help
3y ago
Aggregating the count of a relationship
Drizzle TeamDTDrizzle Team / help
2y ago
How to get findMany with count?
Drizzle TeamDTDrizzle Team / help
2y ago