Describe the bug
I am trying to use an include subquery in my query.
The query seems to work fine, console.log shows that the productionOrder[0] has the part array (it is a 1:1 relation but currently using toArray is the only way of materializing includes) with the correct part found, but when I access the productionOrders[0].part to get the array (then I will access the part[0] to get the part), it is empty, this should be impossible, it does not make any sense 🤯🤯🤯
To Reproduce
- Create a Live Query with an include, a 1:1 relation. In my case:
export function useQueryProductionOrderTable() {
return useLiveQuery((q) =>
q.from({ productionOrder: productionOrderCollection }).select(({ productionOrder }) => ({
...productionOrder,
...
part: toArray(
q
.from({ part: partCollection })
.where(({ part }) => eq(part.id, productionOrder.partId))
.select(({ part }) => ({
...part,
shape: toArray(q.from({ shape: shapeCollection }).where(({ shape }) => eq(shape.id, part.shapeId))),
),
...
})),
),
...
})),
);
}
- Execute query
const { data: productionOrders } = useQueryProductionOrderTable();
console.log("productionOrders[0]:", productionOrders[0]); // This shows that there is a "part" attribute which is an array WITH 1 ELEMENT
console.log("productionOrders[0].part:", productionOrders[0]?.part); // THIS LOGS AN EMPTY ARRAY ????????
Expected behavior
The query should return the linked part to the productionOrder properly due to the toArray call to materialize the collection instance
Screenshots
- Device: [e.g. iPhone6]
- OS: Windows
- Browser: Brave
- Version
@tanstack/electric-db-collection: 0.3.3
@tanstack/react-db: 0.1.83
STACKBLITZ REPRODUCIBLE EXAMPLE:
https://stackblitz.com/~/github.com/Jaime02/tanstack-db-query-include
I guess that toArray return type should include undefined because that is what is returned while the included collection is loading
Describe the bug
I am trying to use an include subquery in my query.
The query seems to work fine,
console.logshows that theproductionOrder[0]has thepartarray (it is a 1:1 relation but currently usingtoArrayis the only way of materializing includes) with the correctpartfound, but when I access theproductionOrders[0].partto get the array (then I will access thepart[0]to get the part), it is empty, this should be impossible, it does not make any sense 🤯🤯🤯To Reproduce
Expected behavior
The query should return the linked
partto theproductionOrderproperly due to thetoArraycall to materialize the collection instanceScreenshots
@tanstack/electric-db-collection: 0.3.3
@tanstack/react-db: 0.1.83
STACKBLITZ REPRODUCIBLE EXAMPLE:
https://stackblitz.com/~/github.com/Jaime02/tanstack-db-query-include
I guess that
toArrayreturn type should includeundefinedbecause that is what is returned while the included collection is loading