How to get the count of relations?

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

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

How can I include a count of inventoryItems in this query? I just want a number of how many inventoryItems have the masterProductId field matching the id field for each row in the masterProducts query
Was this page helpful?