© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•14mo ago•
3 replies
Johnny

Filter on included relations

Hello! Hope you're all doing well!
Is it possible to filter based on included relations?
return await this.db.query.myTable.findMany({
      with: {
        relations: true,
      },
      where: (doc, { and, eq, inArray }) => {
        const predicates: SQL[] = [];
        predicates.push(
          eq(schema.relationTable.type, "my-type"),
        );
        predicates.push(
          eq(schema.relationTable.value, value.toString()),
        );

        return predicates.length > 0 ? and(...predicates) : undefined;
      },
    });
return await this.db.query.myTable.findMany({
      with: {
        relations: true,
      },
      where: (doc, { and, eq, inArray }) => {
        const predicates: SQL[] = [];
        predicates.push(
          eq(schema.relationTable.type, "my-type"),
        );
        predicates.push(
          eq(schema.relationTable.value, value.toString()),
        );

        return predicates.length > 0 ? and(...predicates) : undefined;
      },
    });
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

Filter included relations
Drizzle TeamDTDrizzle Team / help
2y ago
Filter Empty Relations out
Drizzle TeamDTDrizzle Team / help
12mo ago
Filter on relations based upon a WITH
Drizzle TeamDTDrizzle Team / help
3y ago
How to define type of table with all relations included?
Drizzle TeamDTDrizzle Team / help
3y ago