You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(objectql): honor expand where filter on lookup/master_detail expansion (#2140)
* fix(objectql): honor expand `where` filter on lookup/master_detail expansion
The expand post-processor batch-loads related records with an `$in` query but
never merged the nested QueryAST `where`, so a documented
`expand: { rel: { where: {...} } }` filter was silently ignored — every related
record came back regardless of the filter. The spec schema and
query-syntax.mdx both advertise the nested `where`.
Merge the nested filter via an explicit `$and` group
(`{ $and: [{ id: { $in } }, nestedAST.where] }`) rather than a shallow spread:
a spread would clobber the `id` constraint when the nested filter also keys
`id`, and is ambiguous for a top-level `$or`/`$and`. The `$and` wrapper is
correct for every FilterCondition shape and is executed by the memory matcher
and the SQL/mongo filter compilers.
`limit`/`offset` are intentionally still NOT propagated: this path batch-loads
every parent's related records in one `$in` query, so a per-parent limit can't
be expressed — forwarding it would globally cap the batch and drop records
other parents need. `orderBy` is likewise not observable here (records are
re-keyed by FK on injection). Docs + schema describe updated to match, with a
guard test asserting limit/offset are not pushed into the expand query.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* chore(changeset): add changeset for expand `where` propagation fix
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Honor a nested `where` filter inside `expand` on lookup/master_detail expansion.
7
+
8
+
The expand post-processor batch-loads related records with an `id $in [...]` query but never merged the nested QueryAST `where`, so a documented `expand: { rel: { where: {...} } }` filter was silently ignored and every related record came back. The nested filter is now AND-merged into the batch query via an explicit `$and` group (`{ $and: [{ id: { $in } }, nestedAST.where] }`) — robust against a nested filter that itself keys `id` or uses a top-level `$or`/`$and`, where a shallow spread would clobber or reorder the constraint.
9
+
10
+
`limit`/`offset`/`orderBy` remain intentionally not honored on the expand path: it batch-loads every parent's related records in one `$in` query and re-keys them per parent by foreign key, so a per-parent page size or ordering can't be expressed there. Docs and the schema `describe()` are updated to match, with a guard test asserting `limit`/`offset` are not pushed into the expand query.
0 commit comments