Let a view field show one field of its related record
Replaces #30438. GitHub marked that PR merged during the stack reorganization: its old base came to contain its commits, and a merged PR cannot be reopened. The code and the review history from #30438 carry over unchanged.
Adds viewField.relationTargetFieldMetadataId, so an added column on a many-to-one relation can show one field of the related record, e.g. Person → Company › Industry (a lookup column).
This is a backend-first foundation. Nothing renders lookup columns until the front end in #30439 lands; until then, a lookup column set through the API or an app manifest still shows the related record itself. The manifest property is documented here anyway because the docs-drift check requires every manifest property to be documented in the PR that adds it.
Changes
- Schema: a nullable FK to
fieldMetadata,ON DELETE CASCADE, with a partial index; it mirrorsviewFilter.relationTargetFieldMetadataId. Fast instance command2.59.0_AddViewFieldRelationTargetFieldMetadataIdFastInstanceCommand_1794606690417. - Lifecycle: deleting or deactivating the target field removes the lookup column instead of leaving a dangling id. The update util resolves both foreign keys in one call.
- Validation (view-field validator, on create and update, using
findFlatEntityByUniversalIdentifier):- only on non-canonical columns of a many-to-one relation;
- the target must belong to the related object and be active;
- the target must not be a relation (one hop);
- on a column owned by an application, only that application can change the target. The target is not overridable, so a workspace change would land on the application's column and be undone by its next sync; it is rejected instead.
- Public surface:
ViewField.relationTargetFieldMetadataIdon the type and on the create and update inputs;nullon update clears it. Manifests carry it asrelationTargetFieldMetadataUniversalIdentifier(documented inlayout/views.mdx). - Every place that builds a view field sets the new property, including a type-only edit to the released 2-26 command (hence the
ci:allow-previous-version-upgrade-mutationlabel). The client SDK and front metadata schema are regenerated.
Stack
Lookup columns show one field of the record a many-to-one relation points to (Company › Address on People); aggregate columns show a count or sum over a one-to-many relation (People › Count on Companies). Each PR targets the one it builds on; retarget it to main once that one merges.
Size counts changed lines outside tests and generated files: S < 300, M 300–800, L > 800.
| PR | What it does | Size | Code | Tests / generated | Builds on |
|---|---|---|---|---|---|
| #30472 👈 | Server: a view field can show one field of its related record (relationTargetFieldMetadataId) | M | +401 −39 | +552 −3 | main |
| #30450 | Server: lookup columns in the view field AI tools | S | +32 | +152 | #30472 |
| #30348 | Front: tables handle several columns of one field | S | +268 −68 | +193 | #30472 |
| #30439 | Front: lookup columns, added from the + menu | L | +945 −225 | +398 −30 | #30348 |
| #30482 | Server + front: aggregate columns (count, sum, avg, min, max) | L | +1200 −268 | +1725 −122 | #30439 |
Independent of this stack: #30347 (nested one-to-many filter / orderBy / first) and #30485 (upsertViewWidget keeps omitted filter group fields and clears them on null), both on main.
Testing
- Integration
view-field-relation-targetcovers:- a lookup accepted on an added column;
- rejections: canonical column, non-relation, one-to-many, a field of another object, a relation target;
- the column removed when its target field is deleted.
- Unit:
validate-flat-view-field-relation-target(including a deactivated target);validate-flat-view-field-relation-target-not-overridden: a workspace change to an application-owned column's target is rejected, while the owning application, and the workspace on its own columns, can change it;- field deactivation side effects, manifest converters and snapshots.
- Server typecheck. The client SDK and front metadata schema were regenerated against a running server with no drift.
Generated by Claude Code