© 2026 Hedgehog Software, LLC

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

Many-to-Many where in far table

I'm trying to
findMany()
findMany()
Pokemon(s) by a type name

pokemons         pokemonsToType          types
========         ===============         =======
- uuid     <---- - pokemon_uuid     ┌--> - uuid
- name           - type_uuid -------┘    - name
pokemons         pokemonsToType          types
========         ===============         =======
- uuid     <---- - pokemon_uuid     ┌--> - uuid
- name           - type_uuid -------┘    - name


querying like this...
await db.query.pokemons.findMany({
  with: {
    pokemonsToTypes: {
      with: {
        type: { // name of the relation is "type"
          where: (t, { eq }) => eq(t.name, "Water"),
        },
      },
    },
  },
})
await db.query.pokemons.findMany({
  with: {
    pokemonsToTypes: {
      with: {
        type: { // name of the relation is "type"
          where: (t, { eq }) => eq(t.name, "Water"),
        },
      },
    },
  },
})


If the
where
where
def. is on the far relation, the result-set is returning item(s) like this:
{
  uuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
  name: 'Venusaur',
  pokemonsToTypes: [
    {
      pokemonUuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
      typeUuid: 'ec7b093f-b3c3-4644-9e07-8e0f853ea891',
      type: null
    },
    {
      pokemonUuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
      typeUuid: 'ed203404-004a-425f-8b83-20163d5fa54c',
      type: null
    }
  ]
}
{
  uuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
  name: 'Venusaur',
  pokemonsToTypes: [
    {
      pokemonUuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
      typeUuid: 'ec7b093f-b3c3-4644-9e07-8e0f853ea891',
      type: null
    },
    {
      pokemonUuid: '8766f8d9-d83b-4363-aab2-87431d46bb4e',
      typeUuid: 'ed203404-004a-425f-8b83-20163d5fa54c',
      type: null
    }
  ]
}


It returned totally wrong records from
pokemons
pokemons
and the pivot table. No of the returned
typeUuid
typeUuid
s are of
type
type
.
name
name
=
'Water'
'Water'
).
Any ideas where I could go wrong? Are
where
where
expressions in relational M:N tables supported?
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

SQLite 'WHERE table.relationship (one to many) > 0'
Drizzle TeamDTDrizzle Team / help
2y ago
How to fetch related table rows in many_to_many
Drizzle TeamDTDrizzle Team / help
3y ago
Nested Where Clause in Many-to-Many relation using Query
Drizzle TeamDTDrizzle Team / help
2y ago
How to add to the database where the table has a many relationship to another table
Drizzle TeamDTDrizzle Team / help
3y ago