orderBy in nested findMany

The docs suggest that I can order a nested findMany (https://orm.drizzle.team/docs/rqb#order-by) Like so:
await db.query.posts.findMany({
orderBy: (posts, { asc }) => [asc(posts.id)],
with: {
comments: {
orderBy: (comments, { desc }) => [desc(comments.id)],
},
},
});
await db.query.posts.findMany({
orderBy: (posts, { asc }) => [asc(posts.id)],
with: {
comments: {
orderBy: (comments, { desc }) => [desc(comments.id)],
},
},
});
But when I attempt to do something similar:
const projects = await db().query.projects.findMany({
with: {
projectInfo: {
orderBy: (projectInfo, { asc }) => [asc(projectInfo.name)]
},
},
});
const projects = await db().query.projects.findMany({
with: {
projectInfo: {
orderBy: (projectInfo, { asc }) => [asc(projectInfo.name)]
},
},
});
I get the type error : Object literal may only specify known properties, and orderBy does not exist in type How can I orderBy an attribute in a nested query? The projectInfo is a one-to-one relation with projects. I want to order projects by projectInfo.name? Is there a way I can do this using the query syntax?
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
1 Reply
Mykhailo
Mykhailo8mo ago
Hello @tomhill! As for now, you can't filter/order projects in nested relations using query syntax. All filters and etc. will be applied to relations, not to the parent (in your case projects). Also, you face error because you can't order/filter in one-to-one relations
Want results from more Discord servers?
Add your server