Skip to content

Relation Widgets

A type: 'relation' field carries a relation: RelationDescriptor (see View Engine → Relation Widgets) and renders as one of six widgets: three defaults, one per relation kind, plus three opt-ins (carousel, summary, colortags).


The three defaults

Kind Default widget Component Renders
many2one search RelationSearchWidget A debounced MUI Autocomplete
many2many tags RelationTagsWidget A chip picker; links are junction rows written immediately, not part of the record's own draft
one2many list RelationListWidget A read-only embedded grid of the inverse-side records
{ name: 'contact_id', label: 'Contact', type: 'relation',
  relation: { entity: 'contact', kind: 'many2one', labelField: 'name' } },
{ name: 'tags', label: 'Tags', type: 'relation',
  relation: { entity: 'tag', kind: 'many2many', via: 'crm_tag', labelField: 'name' } },

Options worth knowing

Option Kind Effect
relation.filter: { col: value } m2o, m2m static server-side scope on every search/prefill — the picker only ever offers matching rows
relation.filterFields: { relatedCol: ownField } m2o scopes the picker by this record's draft, merged over filter, left out while the own field is empty (a task's stage offers only its project's stages: { project_id: 'project_id' })
relation.formPath: '/x/:id' o2m clicking a row opens that record's own form
relation.inside: { field, zone } o2m instead of inverseField: the records whose point lies in this record's zone (Geographic Widgets)
widgetOptions.fillFields: { col: field } m2o picking a record copies its columns into sibling fields (e.g. an invoice's bill-to snapshot) — no extra fetch
widgetOptions.deletable o2m a trash column; the row disappears only once Go confirms the delete
widgetOptions.reverse o2m newest first (order=-created_at)

Editing a one-to-many row

Double-clicking a row of an o2m table (line items, billing lines…) opens the create dialog on that row: the draft starts from it, Save goes through RelationOps.update, and the inverse foreign key stays hidden. It is off on a read-only form and on a table with formPath (whose click opens the row's own form). After a create or an edit the table refetches its page (Go recomputes a line's totals) and the form's totals/recap follows.

Paged one-to-many grids

When the host binds RelationOps.listPage (the shell does), the embedded o2m grid is server-paged: one request per page, sorted by created_at so pages are stable, 10 rows by default; a rows-per-page selector (25/50/100) appears once the linked rows don't fit. Deleting a row reloads the page so it refills. Without listPage it loads the first 100 rows once. A wide grid scrolls horizontally inside its own box.

The many2one search widget's dropdown appends a synthetic "+ Create new" option after its (max 6) results. Picking it opens RelationCreateWizard, a real form dialog that reuses the related entity's own registered form descriptor — seed defaults, on_change, compute, and permission checks all behave exactly as they would on that entity's real form. A preset seeds and hides fields the caller already knows (e.g. the inverse FK for an o2m context). This is the mechanism behind "add a new contact without leaving the CRM form."

// o2m override — photo-gallery carousel over embedded rows, each backed by a boolean/picture field
{ name: 'photos', label: 'Photos', type: 'relation', widget: 'carousel',
  relation: { entity: 'equipment_photo', kind: 'one2many', inverseField: 'equipment_id' } }

// many2one override — an inline card summarizing the linked record instead of a search box
{ name: 'primary_contact_id', label: 'Primary Contact', type: 'relation', widget: 'summary',
  relation: { entity: 'contact', kind: 'many2one' } }

propertymanagement's Equipment "Photos" field is the shipped carousel example.

Color tags

widget: 'colortags' (RelationColorTagsWidget) is a many2many-only opt-in for related records carrying a color (widgetOptions.colorField, default 'color'): chips with a color dot, in junction creation order (the order Gantt stripes follow). Its "Create a new …" line opens a dialog asking only a name and a color, creates the record, then links it. Read-only ⇒ chips only. Colors reach CSS only as plain #rrggbb; the storing service should validate them too (Project's project_color answers 422 otherwise).

// core/modules/project/views/project_views.ts
{ name: 'color_groups', label: 'Color groups', type: 'relation', widget: 'colortags',
  relation: { entity: 'project_color', kind: 'many2many', via: 'project_task_color',
              viaFields: { own: 'task_id', related: 'color_id' }, labelField: 'name' } }

A list naming this field in viewModeDefaults.colorTagsField paints its records with these colors (see Gantt View).

Batched many-to-many resolution

Resolving a set of linked records from a set of junction rows is one call, not one per row: resolveManyToManyLinks fetches the junction list, then a single ops.list(relatedEntity, { in: { id: [...] } }) — reusing the ORM's in[column] filter (see ORM → Query Parameters). Both tags and summary's nested resolver share this one helper; a dangling junction row (its related record since deleted) falls back to showing the raw id as a placeholder label rather than erroring. See ADR-018 — this is the REST answer to the N+1 problem GraphQL is usually reached for.

Still open: the carousel's own N+1

The carousel widget's per-slide picture-metadata lookup is a different N+1 shape (one anchor per binary resource) that ADR-018 explicitly left open — fixing it needs a batch endpoint on Object Storage that doesn't exist yet.