© 2026 Hedgehog Software, LLC

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

How to filter query based on children table?

Hi friends, first time using Drizzle so be gentle, this question may be dumb.

I designed a model where I have a country table and a country_language table, as you can see in the attachment.

Let's say that I want to return the country which has the slug (from the country_language table)="portugal-en". How can I write that expression?

Here's my try:
const country = await db.query.countries.findFirst({
  with: {
    countryLanguages: {
      where: eq(countryLanguages.slug, countrySlug),
    }
  },
});
const country = await db.query.countries.findFirst({
  with: {
    countryLanguages: {
      where: eq(countryLanguages.slug, countrySlug),
    }
  },
});


However, this is returning the first country and then just filtering the country_languages table, which is not what I want. I tried to move the where clause to the country level, but didn't worked, since that column (slug) does not exist on the country table).

Thank you!
image.png
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
how to query based on relation?
Drizzle TeamDTDrizzle Team / help
2y ago
Complex filter on query.
Drizzle TeamDTDrizzle Team / help
11mo ago
Relational Queries: How to query based on the value of a joined table?
Drizzle TeamDTDrizzle Team / help
3y ago