Skip to content

feat(objectql): compute roll-up summary fields server-side#1610

Merged
xuyushun441-sys merged 2 commits into
mainfrom
feat/summary-rollup-fields
Jun 6, 2026
Merged

feat(objectql): compute roll-up summary fields server-side#1610
xuyushun441-sys merged 2 commits into
mainfrom
feat/summary-rollup-fields

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

Summary

The summary field type was declared in @objectstack/spec but 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/avg over 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/spec

  • summaryOperations gains optional relationshipField (the child→parent FK). Auto-detected from the child's lookup/master_detail field whose reference points back at the parent when omitted.

@objectstack/objectql

  • After afterInsert/afterUpdate/afterDelete on 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.
  • Runs in the caller's execution context → when a transaction is open (e.g. the cross-object /api/v1/batch) the rollup commits atomically with the child writes.
  • Lazy child→summary descriptor index, invalidated on package registration.
  • Empty collections → 0 for count/sum, null for min/max/avg.

Showcase

  • showcase_project.task_count (COUNT) + total_estimate (SUM of showcase_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).
  • Full objectql 530 + spec 6646 suites pass.
  • Live-verified against the real SQL driver via /api/v1/batch (objectui e2e/live/summary-rollup.spec.ts, 2 passing): SUM/COUNT computed on atomic create; recomputed to 0 on child delete.

🤖 Generated with Claude Code

os-zhuang and others added 2 commits June 6, 2026 18:08
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>
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Building Building Preview, Comment Jun 6, 2026 10:39am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation protocol:data tests tooling size/m labels Jun 6, 2026
@xuyushun441-sys xuyushun441-sys merged commit 9e2e229 into main Jun 6, 2026
10 of 11 checks passed
@xuyushun441-sys xuyushun441-sys deleted the feat/summary-rollup-fields branch June 6, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:data size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants