Files
twenty/packages
Thomas Trompette 2514cab860 fix(server): include relation join column names in updatedFields of update events (#21405)
## Context

Since #21052, update-event diffs are keyed by the relation field name
(e.g. `company`) instead of the join column name (e.g. `companyId`).
`updatedFields` is derived from the diff keys, so any **workflow
database-event trigger** (or webhook) configured with a field filter on
a relation join column **silently stopped firing** — no run is created
at all.

We hit this in production: a `cloudWorkspace.updated` trigger filtered
on `twentyContactId` stopped creating runs the same day #21052 was
deployed. Updating the record's relation produced `updatedFields:
["twentyContact"]`, which no longer matches the stored settings `fields:
["twentyContactId"]` in
`WorkflowDatabaseEventTriggerListener.shouldTriggerJob`.

## Solution

Keep the diff keyed by relation field name (the timeline rendering from
#21052 relies on it — adding both keys to the diff would display
relation changes twice), but expose **both** the relation field name and
its join column name in `updatedFields`:

- New `computeUpdatedFieldsFromDiff()` in
`object-record-changed-values.ts`: expands MANY_TO_ONE relation diff
keys with their join column name.
- Used in `formatTwentyOrmEventToDatabaseBatchEvent` for
UPDATED/DELETED/RESTORED and UPSERTED events instead of
`Object.keys(diff)`.

This restores matching for pre-existing trigger/webhook configurations
(join column names) while keeping configurations using relation field
names working.

## Test plan

- [x] Unit tests: relation diff keyed by relation name; `updatedFields`
contains both `company` and `companyId`
- [x] End-to-end util test on UPDATED event: `updatedFields: ['company',
'companyId']`, diff keyed by `company`
- [x] Downstream consumer specs pass (workflow trigger listener,
webhooks, subscriptions, logic-function triggers)
- [x] Verified against the production workspace that a `twentyContactId`
update currently produces no workflow run with the old behavior
2026-06-10 14:48:24 +00:00
..