Skip to content
Source
Sign inSign up
TanStack/db

fix(db): avoid passing computed orderBy aliases to loadSubset #1520

Closedandrewcoelho(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1520/headopened

Showing 5 changed files with 21 additions and 12 deletions (loading 2).

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/fix-load-subset-order-by-hints.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Fix `loadSubset` orderBy hints for subqueries with computed selected fields. We now stop ref-following on non-ref select expressions and only pass `orderBy`/`limit` hints when each `orderBy` ref resolves to a real source field.
8 additions and 6 deletionspackages/db/src/query/compiler/index.tsModified
View file
@@ -1107,15 +1107,17 @@
// is it part of the select clause?
if (query.select) {
const selectedField = query.select[field]
- if (selectedField && selectedField.type === `ref`) {
- return followRef(query, selectedField, collection)
+ if (selectedField) {
+ // Only pass-through refs can be followed to a raw collection field.
+ // Computed select expressions do not map to a source column.
+ if (selectedField.type === `ref`) {
+ return followRef(query, selectedField, collection)
+ }
+ return
- // Either this field is not part of the select clause