© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
tomhill

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
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
query
syntax?
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Select in nested findMany query ?
Drizzle TeamDTDrizzle Team / help
2y ago
Get the count of a nested relation in findMany()
Drizzle TeamDTDrizzle Team / help
17mo ago
NULLS LAST in orderBy
Drizzle TeamDTDrizzle Team / help
16mo ago
Orderby in including relations
Drizzle TeamDTDrizzle Team / help
2y ago