Why it's not possible to use `where` here?

I'm trying to make a PoC for drizzle and I'm converting some sequelize to Drizzle, but I don't really have experience with databases to be honest with you. I can't understand, why using where is not possible in this case. Seems like I don't quite understand how to describe BelongsTo with Drizzle and that might be a problem. Can you guys help? Thanks
No description
No description
5 Replies
aveatrex
aveatrex17mo ago
you can't use where with a one relation but if you want to retrive the account of an accountContact, all you need is
with: { account: true }
with: { account: true }
and you would use where on findMany to filter by the accountContact
aquarazorda
aquarazordaOP17mo ago
Thanks for the reply. In sequelize, I’m filtering results like that. So, account has vendorId and I need to filter out data with it. What would be the way to achieve this with drizzle? I can’t change db structure.
aveatrex
aveatrex17mo ago
GitHub
Release 0.28.0 · drizzle-team/drizzle-orm
Breaking changes Removed support for filtering by nested relations Current example won't work in 0.28.0: const usersWithPosts = await db.query.users.findMany({ where: (table, { sql }) => (...
aveatrex
aveatrex17mo ago
but i think you can work around it in your case if you go from account
db.query.accountSchema.findMany({
where: // filter with vendorId
with: {
accountContactSchema: {
with: {
authenticatedUser: ...
}

}
}
})
db.query.accountSchema.findMany({
where: // filter with vendorId
with: {
accountContactSchema: {
with: {
authenticatedUser: ...
}

}
}
})
aquarazorda
aquarazordaOP17mo ago
Gotcha, so I have to use it other way around and there’s no way to persist the data, like in sequelize was. Thanks a lot! @aveatrex
Want results from more Discord servers?
Add your server