© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•17mo ago•
6 replies
much 2 yearn

Where clause on 'with' in findMany

export const getOrgsByMembershipList = cache(async () => {
  const user = await getAuthUser();

  if (!user) {
    throw new Error("User not found");
  }

  const result = await db.query.membership.findMany({
    where: eq(membership.profileId, user.id),
    with: {
      org: {
        columns: {
          id: true,
          name: true,
        },
        where: eq(org.defaultOrg, false),
      },
    },
  });

  return result;
});
export const getOrgsByMembershipList = cache(async () => {
  const user = await getAuthUser();

  if (!user) {
    throw new Error("User not found");
  }

  const result = await db.query.membership.findMany({
    where: eq(membership.profileId, user.id),
    with: {
      org: {
        columns: {
          id: true,
          name: true,
        },
        where: eq(org.defaultOrg, false),
      },
    },
  });

  return result;
});
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

Trouble using findMany with joined relation and where clause on relation
Drizzle TeamDTDrizzle Team / help
2y ago
Missing where in findMany with
Drizzle TeamDTDrizzle Team / help
2y ago
Where clause dependent on with relation
Drizzle TeamDTDrizzle Team / help
2y ago
Multiple subquery on where condition in findMany
Drizzle TeamDTDrizzle Team / help
3y ago