[Bug] Relation fields created in modern UI are missing from block field lists due to invalid `source` metadata
* Describe the bug
Many-to-one fields created through the modern collection editor are saved successfully but do not appear in the field lists when configuring UI blocks.
The fields exist in persisted collection metadata returned by collections:get, but are missing from collections:listMeta, which the modern UI uses to load collection definitions.
The modern FieldForm automatically sets source to the current collection name:
set(values, 'source', props.collection.name);However, the backend Collection.setField interprets source as a reference in the format collection.field. When it receives only a collection name, it looks for an undefined source field and skips loading the relation.
This was observed for two independently created m2o fields. Reloading the browser, clearing the cache, and restarting the container did not resolve the issue.
Setting source to null through the Data Modeling API restored both fields in collections:listMeta, while preserving their relation keys.
* Environment
NocoBase version: 2.2.19
Database type and version: PostgreSQL 16.14
OS: Linux Docker environment; host distribution not recorded
Deployment Methods: Docker
Docker image version:
nocobase/nocobase:latest-full; installed NocoBase version 2.2.19
* How To Reproduce
Open the collection editor in the modern UI.
Create a general collection, for example
tasks.Add a scalar foreign-key field
actor_idcompatible withusers.id.Through the collection editor, add a many-to-one field:
- Field name:
actor - Target collection:
users - Foreign key:
actor_id - Target key:
id
- Field name:
Save the field.
Create or open a table block using
tasks.Open the field configuration list. The
actorrelation is missing.Inspect the saved collection definition using
collections:getwithappends=fields. The relation exists, with metadata equivalent to:{ "name": "actor", "interface": "m2o", "type": "belongsTo", "collectionName": "tasks", "source": "tasks", "target": "users", "foreignKey": "actor_id", "targetKey": "id" }Inspect
collections:listMeta. Theactorfield is absent from the runtime collection definition.Reload the browser or restart NocoBase. The field remains unavailable.
The metadata-level failure was also reproduced locally on NocoBase 2.2.19: a relation with source set to the collection name was persisted but absent from collections:listMeta. Changing only the problematic source value to null, while preserving the relation definition, made it appear in the runtime metadata.
Expected behavior
Relations created through the collection editor should load into the runtime collection definition and be available when configuring UI blocks.
The display-only “Source collection” value should not be persisted as the backend field-reference attribute source.
Screenshots
No screenshots attached. The discrepancy is observable by comparing the persisted and runtime metadata responses described above.
Logs
No relevant server log excerpt was captured. The metadata requests returned HTTP 200 rather than an API error.
The backend code path explains the missing runtime field:
const [sourceCollectionName, sourceFieldName] = options.source.split('.');
const sourceField = sourceCollection.fields.get(sourceFieldName);For source: "tasks", sourceFieldName is undefined. When the source field cannot be found, Collection.setField logs a warning and returns null.
Relevant source files:
packages/plugins/@nocobase/plugin-data-source-manager/src/client-v2/pages/components/FieldForm.tsx— assigns the collection name tosourceduring relation initialization and interface changes.packages/core/database/src/collection.ts— interpretssourceascollection.fieldand skips fields whose source cannot be resolved.
The erroneous assignment was also confirmed in the JavaScript bundle installed in the affected production container.
Source: nocobase/nocobase