T
TanStack2mo ago
noble-gold

Multiple Joins "Invalid join condition"

I'm having this issue when i'm trying to This are my collections nothing fancy
const playersCollection = createCollection(
queryCollectionOptions({
queryKey: ["jugadores", clubId],
queryFn: async () => {
const results = await call.get<FrappeResponse<Jugador[], { count: number }>>(
"setplus.setplus.doctype.jugador.jugador.get_filtered_jugadores",
{
club: clubId,

page_size: 9999999,
page: 0,
},
);
return results.message.data ?? [];
},
getKey: (item) => item.name,
queryClient,
}),
);
const clientsCollection = createCollection(
queryCollectionOptions({
queryClient,
queryKey: ["clientes", clubId],
queryFn: async () => {
return await db.getDocList<Cliente>("Cliente", {
filters: [["club", "=", clubId]],
fields: ["*"],
limit: 9999999,
});
},
getKey: (item) => item.name,
}),
);
const balancesCollection = createCollection(
queryCollectionOptions({
queryClient,
queryKey: ["balances", clubId],
queryFn: async () => {
return await db.getDocList<BalanceClientePorClub>("Balance Cliente por Club", {
filters: [["club", "=", clubId]],
fields: ["*"],
limit: 9999999,
});
},
getKey: (item) => item.name,
}),
);
const playersCollection = createCollection(
queryCollectionOptions({
queryKey: ["jugadores", clubId],
queryFn: async () => {
const results = await call.get<FrappeResponse<Jugador[], { count: number }>>(
"setplus.setplus.doctype.jugador.jugador.get_filtered_jugadores",
{
club: clubId,

page_size: 9999999,
page: 0,
},
);
return results.message.data ?? [];
},
getKey: (item) => item.name,
queryClient,
}),
);
const clientsCollection = createCollection(
queryCollectionOptions({
queryClient,
queryKey: ["clientes", clubId],
queryFn: async () => {
return await db.getDocList<Cliente>("Cliente", {
filters: [["club", "=", clubId]],
fields: ["*"],
limit: 9999999,
});
},
getKey: (item) => item.name,
}),
);
const balancesCollection = createCollection(
queryCollectionOptions({
queryClient,
queryKey: ["balances", clubId],
queryFn: async () => {
return await db.getDocList<BalanceClientePorClub>("Balance Cliente por Club", {
filters: [["club", "=", clubId]],
fields: ["*"],
limit: 9999999,
});
},
getKey: (item) => item.name,
}),
);
6 Replies
noble-gold
noble-goldOP2mo ago
And this is my live query
const { data } = useLiveQuery((q) =>
q
.from({ player: playersCollection })
.join({ client: clientsCollection }, ({ client, player }) => eq(client.player, player.name))
.join({ balance: balancesCollection }, ({ balance, client }) => eq(balance.client, client.name))
.select(({ player, client, balance }) => ({
player,
client,
balance,
})),
);
const { data } = useLiveQuery((q) =>
q
.from({ player: playersCollection })
.join({ client: clientsCollection }, ({ client, player }) => eq(client.player, player.name))
.join({ balance: balancesCollection }, ({ balance, client }) => eq(balance.client, client.name))
.select(({ player, client, balance }) => ({
player,
client,
balance,
})),
);
when i add the third join i get this error
Invalid join condition: expressions reference tables "balance" and "client" but join is between "player" and "balance"
Invalid join condition: expressions reference tables "balance" and "client" but join is between "player" and "balance"
unwilling-turquoise
unwilling-turquoise2mo ago
Looks like a bug — could you file an issue?
noble-gold
noble-goldOP2mo ago
oka, let me do it tomorrow, do you need a stackblitz?
noble-gold
noble-goldOP2mo ago
GitHub
Multiple Joins "Invalid join condition" · Issue #474 · TanStack/db
Stackblitz https://stackblitz.com/edit/vitejs-vite-gnkg2sdh?file=src%2FApp.tsx I&#39;m having this issue when i&#39;m trying to This are my collections nothing fancy const playersCollection = creat...
noble-gold
noble-goldOP4w ago
work around
q
.from({ client: clientsCollection })
.join({ player: playersCollection }, ({ client, player }) =>
eq(player.name, client.jugador)
)
.join({ balance: balancesCollection }, ({ balance, client }) =>
eq(client.name, balance.client)
)
.select(({ player, client }) => ({ player, client }))
q
.from({ client: clientsCollection })
.join({ player: playersCollection }, ({ client, player }) =>
eq(player.name, client.jugador)
)
.join({ balance: balancesCollection }, ({ balance, client }) =>
eq(client.name, balance.client)
)
.select(({ player, client }) => ({ player, client }))

Did you find this page helpful?