Let a view field show one field of its related record

Merged
FE
3h ago
+952-42

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 mirrors viewFilter.relationTargetFieldMetadataId. Fast instance command 2.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.relationTargetFieldMetadataId on the type and on the create and update inputs; null on update clears it. Manifests carry it as relationTargetFieldMetadataUniversalIdentifier (documented in layout/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-mutation label). 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.

PRWhat it doesSizeCodeTests / generatedBuilds on
#30472 👈Server: a view field can show one field of its related record (relationTargetFieldMetadataId)M+401 −39+552 −3main
#30450Server: lookup columns in the view field AI toolsS+32+152#30472
#30348Front: tables handle several columns of one fieldS+268 −68+193#30472
#30439Front: lookup columns, added from the + menuL+945 −225+398 −30#30348
#30482Server + 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-target covers:
    • 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