Filter included relations

I am currently using the following query to retrieve all undeleted 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 can be assigned to an appChannel. Currently, all undeleted appBundles are returned, regardless of whether the associated appChannel has been deleted or not. In the future, I only want to query appBundles whose 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?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server