© 2026 Hedgehog Software, LLC

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

Filter included relations

I am currently using the following query to retrieve all undeleted
appBundles
appBundles
from my database:

const selectedAppBundles = await db.query.appBundles.findMany({
  where: (appBundles, { isNull }) => isNull(appBundles.deletedAt),
  orderBy: (appBundles, { desc }) => desc(appBundles.createdAt),
  offset,
  limit,
  with: {
    appChannel: true,
  },
});
const selectedAppBundles = await db.query.appBundles.findMany({
  where: (appBundles, { isNull }) => isNull(appBundles.deletedAt),
  orderBy: (appBundles, { desc }) => desc(appBundles.createdAt),
  offset,
  limit,
  with: {
    appChannel: true,
  },
});


Each
appBundle
appBundle
can be assigned to an
appChannel
appChannel
. Currently, all undeleted
appBundles
appBundles
are returned, regardless of whether the associated
appChannel
appChannel
has been deleted or not. In the future, I only want to query
appBundles
appBundles
whose
appChannel
appChannel
is not deleted, if one is assigned.

Unfortunately, the following does not work:

const selectedAppBundles = await db.query.appBundles.findMany({
  where: (appBundles, { and, isNull }) => and(isNull(appBundles.deletedAt), isNull(appChannels.deletedAt)),
  orderBy: (appBundles, { desc }) => desc(appBundles.createdAt),
  offset,
  limit,
  with: {
    appChannel: true,
  },
});
const selectedAppBundles = await db.query.appBundles.findMany({
  where: (appBundles, { and, isNull }) => and(isNull(appBundles.deletedAt), isNull(appChannels.deletedAt)),
  orderBy: (appBundles, { desc }) => desc(appBundles.createdAt),
  offset,
  limit,
  with: {
    appChannel: true,
  },
});


What is the best way to implement this?
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 on included relations
Drizzle TeamDTDrizzle Team / help
14mo 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