#10489·nocobase

当 NocoBase Skill 使用通用 o2o 创建反向一对一字段时,可能会导致关联方向错误

作者: Roc-kit创建于 2026年9月9日更新于 2026年9月11日

Environment

  • NocoBase: 2.2.6
  • Use the official NocoBase Skill to create data models
  • Involves one-to-one related fields

Problem description

When we use the official NocoBase Skill to create one-to-one relationships, we encountered the problem that the relationship direction was created incorrectly. When we created fields according to the instructions and examples in the Skill about one-to-one relationships, the reverse field used the general one:

json
{
  "interface": "o2o"
}

After the actual creation was completed, we found that the direction of the one-to-one relationship was inconsistent with the expected one, and the foreign key side also had errors. Further inspection of the source code of NocoBase 2.2.6 in actual operation found that the one-to-one relationship was actually clearly distinguished as:

obo = belongsTo
oho = hasOne

The reverse relationship of the two should also be clearly corresponding:

obo -> reverseField: oho
oho -> reverseField: obo

For example, if the A table stores the foreign key of B, the expected relationship should be:

A -> B: obo / belongsTo
B -> A: oho / hasOne

However, in the one-to-one example of the current Skill, there are similar statements:

json
{
  "name": "profile",
  "interface": "m2o",
  "target": "profiles",
  "foreignKey": "profileId",
  "reverseField": {
    "name": "user",
    "interface": "o2o"
  }
}

This type of statement. In our actual use, the Agent generates the related fields according to this rule, and the reverse field direction is created incorrectly; after changing the relationship to the clear obo / oho, the relationship direction is consistent with the expected one.

Expected behavior

For one-to-one relationships, we hope that the official Skill will clearly use:

obo = belongsTo
oho = hasOne

Instead of using the general o2o in places where it is necessary to specify the direction. For example:

json
{
  "name": "profile",
  "interface": "obo",
  "target": "profiles",
  "foreignKey": "profileId",
  "reverseField": {
    "name": "user",
    "interface": "oho"
  }
}

内容来源: nocobase/nocobase