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;
});
4 Replies
much 2 yearn
much 2 yearnOP2mo ago
Object literal may only specify known properties, and 'where' does not exist in type '{ columns?: tried to follow docs but trying to add a where clause on the org did not work
megamindat
megamindat2mo ago
I can't seem to make it work either. I'm doing something like this:
with: {
address: {
where: (address, { and, isNull }) =>
and(isNull(address.customerID), isNull(address.userID)),
columns: {
addressLine1: true,
city: true,
state: true,
zipCode: true,
note: true,
},
},
with: {
address: {
where: (address, { and, isNull }) =>
and(isNull(address.customerID), isNull(address.userID)),
columns: {
addressLine1: true,
city: true,
state: true,
zipCode: true,
note: true,
},
},
Please help @Angelelz @Raphaël M (@rphlmr) ⚡ , thank you! 🙂
rphlmr ⚡
rphlmr ⚡2mo ago
👋 there is no where clause if your relation is not a many. If org is a one and address too, it's not possible the way this api works.
megamindat
megamindat2mo ago
Oh got it, thanks @Raphaël M (@rphlmr) ⚡ .
Want results from more Discord servers?
Add your server