drizzle-orm
drizzle-orm copied to clipboard
Support nested orderBy
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,
})