© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
Vision2023

How to use nested joins with relational query builder

I have a query like this:
const templates = await db.query.productSetTemplates.findMany({
      limit: 12,
      offset: /* not important */,
      orderBy: /* not important */,
      where: /* not important */,
      with: {
        productSet: {
          with: {
            products: {
              limit: 1
            }
          }
        },
        prototypeProductSets: {
          with: {
            products: {
              columns: {
                id: true
              }
            }
          }
        }
      }
    })
const templates = await db.query.productSetTemplates.findMany({
      limit: 12,
      offset: /* not important */,
      orderBy: /* not important */,
      where: /* not important */,
      with: {
        productSet: {
          with: {
            products: {
              limit: 1
            }
          }
        },
        prototypeProductSets: {
          with: {
            products: {
              columns: {
                id: true
              }
            }
          }
        }
      }
    })


I want to transform it to use relational query builder. I'm having problem with nested joins. How do I do this.

I want to use rqb because, I have to make another query somewhere else and i think I shouldn't need to make that extra query if I use rqb.
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

advanced relational query builder
Drizzle TeamDTDrizzle Team / help
3y ago
How to do conditional joins with the query builder?
Drizzle TeamDTDrizzle Team / help
3y ago
Relational query builder in mysql?
Drizzle TeamDTDrizzle Team / help
3y ago
How to raise nested fields in relational query results?
Drizzle TeamDTDrizzle Team / help
3y ago