© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
3 replies
migs

Querying table based on a field of a related table

Hey everyone, I have no idea what im doing wrong, but the goal here is to get every subscription which its related plan, has the spaceId field according to an input. Here's what I got after reading the docs:

const subscriptions = await ctx.db.query.subscriptions.findMany({
with: {
plan: {
where: (plan, { eq }) => eq(plans.spaceId, input.spaceId),
},
},
});

Typescript is complaining on the "where" , saying I can't use it here. I saw a very similar example on the docs:

await db.query.posts.findMany({
where: (posts, { eq }) => (eq(posts.id, 1)),
with: {
comments: {
where: (comments, { lt }) => lt(comments.createdAt, new Date()),
},
},
});

The only difference is the type of relation, where in my case subscription has a relation with one plan, and the example on the docs the posts have a relation of many comments. Should I be querying for plans and filtering the subscriptions from there? Doesn't feel right when in fact what I want is the subscriptions.
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

Query a table based on related table
Drizzle TeamDTDrizzle Team / help
3y ago
Querying based on record in another table
Drizzle TeamDTDrizzle Team / help
3y ago
Querying PG table by JSONB field
Drizzle TeamDTDrizzle Team / help
3y ago
Filter based querying
Drizzle TeamDTDrizzle Team / help
2y ago