drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

Support nested orderBy

Open steebchen opened this issue 1 month ago • 0 comments

Describe what you want

Assuming I have a table tags and products with a many-to-many relation on table productsToTags. I would like to query by a few specific tag IDs and order it by the most popular products. However, this is not possible right now because the orderBy does not include the product info.

const products = await db().query.tags.findMany({
  with: {
    productsToTags: {
      with: {
        product: true,
      },
                                      // .product is undefined
      orderBy: (pt, { desc }) => [desc(pt.product.popularity)],
    },
  },
  limit: 3,
})

steebchen avatar May 10 '24 17:05 steebchen