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),
    }
  },
});


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
Was this page helpful?