Skip to content

seed-loader: 多值 lookup(multiple: true)的自然键数组被静默丢弃,记录落库但整个关联字段缺失 #3911

Description

@yinlianghui

环境

  • @objectstack/metadata-protocol 16.1.0(17.0.0-rc.0 亦复现)
  • 种子经 defineSeed() 定义,随应用启动加载

最小复现

// author.object.ts
export const Author = ObjectSchema.create({
  name: 'author',
  fields: { name: Field.text({ label: 'Name', required: true }) },
});

// book.object.ts
export const Book = ObjectSchema.create({
  name: 'book',
  fields: {
    name: Field.text({ label: 'Title', required: true }),
    authors: Field.lookup('author', { label: 'Authors', multiple: true }),
  },
});

// seeds
const authors = defineSeed(Author, {
  mode: 'upsert', externalId: 'name',
  records: [{ name: 'Alice' }, { name: 'Bob' }],
});
const books = defineSeed(Book, {
  mode: 'upsert', externalId: 'name',
  records: [{ name: 'Refactoring', authors: ['Alice', 'Bob'] }],
});

启动应用(objectstack dev)触发种子加载。

实际结果

  • book 记录成功落库,但 authors 字段整个缺失(查库 / GET /api/v1/data/book 均无该字段值)
  • 种子加载不报错、不中断,仅在日志出现一条 warn:
[SeedLoader] Invalid reference for book.authors: expected a author.name natural-key string but got an object. Pass the target's name value as a plain string.
  • 提示 "Pass … as a plain string",但该字段是 multiple: true,无法用单个字符串表达多个关联
  • 对比:单值 lookup 传字符串自然键(如 crm_account: 'Acme' 形式)解析正常

预期结果

多值 lookup 字段传自然键数组时,能像单值字段的字符串自然键一样逐个解析为目标记录 id 并写入;或至少加载结果向调用方明确报错,而不是记录成功、字段静默消失。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions