T
TanStack2mo ago
conscious-sapphire

subquery doesn't work in join

// not work
const { data: a } = useLiveQuery((q) =>
q.from({ product: productsCollection })
.leftJoin({ tried: createTriedByUserId(user?.id, true) }, ({ tried, product }) => eq(tried.productId, product.id))
)

// work
const { data: a } = useLiveQuery((q) =>
q.from({ tried: createTriedByUserId(user?.id, true) })
.leftJoin({ product: productsCollection }, ({ tried, product }) => eq(tried.productId, product.id))
)
// not work
const { data: a } = useLiveQuery((q) =>
q.from({ product: productsCollection })
.leftJoin({ tried: createTriedByUserId(user?.id, true) }, ({ tried, product }) => eq(tried.productId, product.id))
)

// work
const { data: a } = useLiveQuery((q) =>
q.from({ tried: createTriedByUserId(user?.id, true) })
.leftJoin({ product: productsCollection }, ({ tried, product }) => eq(tried.productId, product.id))
)
12 Replies
conscious-sapphire
conscious-sapphireOP2mo ago
export function createTriedByUserId(userId?: number, notTried: boolean = false) {
return new Query().from({ tried: triedsCollection })
.where(({ tried }) => {
if (notTried) {
return eq(tried.userId, userId)
}

return and(
eq(tried.userId, userId),
not(eq(tried.createdAt, null))
)
})
}
export function createTriedByUserId(userId?: number, notTried: boolean = false) {
return new Query().from({ tried: triedsCollection })
.where(({ tried }) => {
if (notTried) {
return eq(tried.userId, userId)
}

return and(
eq(tried.userId, userId),
not(eq(tried.createdAt, null))
)
})
}
eager-peach
eager-peach2mo ago
can you file a bug report on github with a small reproduction e.g. in stackblitz?
conscious-sapphire
conscious-sapphireOP2mo ago
idk if i should file an issue because that only happen when theres no delay in the queryFn but its happen sometimes even if i have an api call so its weird the query doesnt refresh it happen in from and join
eager-peach
eager-peach2mo ago
no yeah, an immediate return should still work so this is definitely a bug of some sort — file away!
conscious-sapphire
conscious-sapphireOP2mo ago
okay im gonna do it
conscious-sapphire
conscious-sapphireOP2mo ago
@Kyle Mathews https://stackblitz.com/edit/vitejs-vite-wwvdzzt1?file=src/db/products-collection.ts,src/db/trieds-collection.ts,src/App.tsx subquery doesn't work in join still idk why yesterday that was working
eager-peach
eager-peach2mo ago
is this a new problem?
conscious-sapphire
conscious-sapphireOP2mo ago
That was the original post problem Thread This convo
eager-peach
eager-peach2mo ago
ok, let's keep bug discussions in github — it's ok to validate them here on discord but github is the best place to post updates
conscious-sapphire
conscious-sapphireOP2mo ago
Im gonna file an issue

Did you find this page helpful?