Best way to get count in extras

await db.query.productSets
  .findMany({
    extras: {
      productsCount:
        sql`(SELECT count(*) from ${products} WHERE "Product"."productSetId" = ${productSets.id})`.as(
          'productsCount'
        )
    },
    with: { products: true }
  })

is there a better way to do this without the sql operator? I want to just use drizzle code (to make more complex queries). if i try to, i get weird issues. similarly, if i replace "Product"."productSetId" with ${products.productSetId}, it tells me productSetId does not exist on the ProductSet table (it uses the wrong table)
Was this page helpful?