feat(objectql): compute roll-up summary fields server-side#1610
Merged
Conversation
fix(master-detail): reliable submit + durable live e2e harness (#1521) objectui@514f426600bcc6284b67909dd7ced7e1bcb1d762
The `summary` field type was declared but never computed. ObjectQL now recomputes a parent's roll-up (count/sum/min/max/avg over a child field) whenever a child is inserted/updated/deleted, in the caller's execution context so it commits atomically inside an open transaction (e.g. the cross-object /api/v1/batch). - spec: summaryOperations.relationshipField (optional; FK auto-detected from the child's lookup/master_detail reference otherwise). - objectql: lazy child→summary index; recompute after afterInsert/ afterUpdate/afterDelete (prior FK captured on update/delete so a re-parented/removed child updates the old parent too). - showcase: project.task_count + total_estimate demonstrate it. Tests: summary-rollup.test.ts (4 — sum/count, update, delete→0, parent isolation); full objectql suite 530 pass, spec 6646 pass. Verified live against the SQL driver via /api/v1/batch (objectui e2e/live/summary-rollup). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
summaryfield type was declared in@objectstack/specbut never computed by the engine — the value stayed empty. This makes it real: ObjectQL recomputes a parent's roll-up summary (count/sum/min/max/avgover a child field) automatically whenever a child record is inserted, updated, or deleted.This is the server-side counterpart to the master-detail work — parent totals no longer need to be summed on the client; the server is the single source of truth.
Changes
@objectstack/specsummaryOperationsgains optionalrelationshipField(the child→parent FK). Auto-detected from the child'slookup/master_detailfield whosereferencepoints back at the parent when omitted.@objectstack/objectqlafterInsert/afterUpdate/afterDeleteon a child, the engine resolves the affected parent (current FK + prior FK on update/delete so a re-parented or removed child updates the old parent too), re-aggregates the child collection, and writes the result onto the parent's summary field./api/v1/batch) the rollup commits atomically with the child writes.0for count/sum,nullfor min/max/avg.Showcase
showcase_project.task_count(COUNT) +total_estimate(SUM ofshowcase_task.estimate_hours) demonstrate the feature.Testing
summary-rollup.test.ts— 4 unit tests (sum + count on insert, recompute on update, delete→0, parent isolation)./api/v1/batch(objectuie2e/live/summary-rollup.spec.ts, 2 passing): SUM/COUNT computed on atomic create; recomputed to 0 on child delete.🤖 Generated with Claude Code