srigi
srigi
Explore posts from servers
DTDrizzle Team
Created by srigi on 5/30/2023 in #help
Many-to-Many where in far table
I'm trying to 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 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 and the pivot table. No of the returned typeUuids are of type.name = 'Water'). Any ideas where I could go wrong? Are where expressions in relational M:N tables supported?
8 replies