Skip to content

feat: add reverse relation mappings#17

Open
inchei wants to merge 2 commits into
bangumi:masterfrom
inchei:master
Open

feat: add reverse relation mappings#17
inchei wants to merge 2 commits into
bangumi:masterfrom
inchei:master

Conversation

@inchei
Copy link
Copy Markdown

@inchei inchei commented May 8, 2026

Copy link
Copy Markdown
Contributor

@trim21 trim21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查:subject_relations.yml 对照 Bangumi 现有代码

审查依据:比对 Bangumi/lib/SubjectRelation.class.phpconvertRelations() 的现有交换集。


Bug:Game→Game 缺少 GAME_VERSION → GAME_MAIN_VERSION(4016 → 4017)

当前 Game→Game 同类型映射中:

*TYPE_GAME :
  *TYPE_GAME :
    *GAME_MAIN_VERSION : *GAME_VERSION      # 4017 → 4016
    *GAME_COLLECTION : *GAME_IN_COLLECTION   # 4018 → 4019
    *GAME_IN_COLLECTION : *GAME_COLLECTION   # 4019 → 4018
    # 缺少:*GAME_VERSION : *GAME_MAIN_VERSION  ← 4016 → 4017

PHP 中对应逻辑同时包含双向:

self::TYPE_GAME_VERSION => self::TYPE_GAME_MAIN_VERSION,      // 4016 → 4017
self::TYPE_GAME_MAIN_VERSION => self::TYPE_GAME_VERSION,      // 4017 → 4016

后果:用户将 A 设为 B 的不同版本(4016) 时,getReverseRelation 找不到映射,fallback 返回 4016 自身,导致反向也是不同版本而非主版本。

建议在 Game→Game 段补充 *GAME_VERSION : *GAME_MAIN_VERSION


行为差异:ANIME_PARENT_STORY (12) 的反向映射

PHP 实际运行时由于 duplicate key 覆盖:

12 => 6,    // 被覆盖
12 => 11,   // 覆盖后生效,Parent Story → Spin-off

实际 PHP 中 PARENT_STORY(12) 反向是 SPIN_OFF(11)

PR 中映射为:

*ANIME_PARENT_STORY : *ANIME_SIDE_STORY    # 12 → 6 而非 11

PR 选择映射到概念更广泛的 SIDE_STORY(番外篇),语义上更合理,但这与 PHP 现有运行时行为不同。需确认是否有存量数据依赖 PHP 的 12 → 11 逻辑。


补充确认点

  1. PHP 中 Game exchange_set 含 4004/4005 幽灵 ID(不在 YAML types 中),YAML 的 relation_ids 未包含,PR 无此问题
  2. 合并后需重新编译 subject_relations.json,当前 JSON 不含 relation_idsrelation_mappings
  3. 跨类型的对称映射(如 Character、Same Setting 等 fallback 到自身)符合预期,book→book 缺少 BOOK_VERSION 映射也属合理

@inchei
Copy link
Copy Markdown
Author

inchei commented May 8, 2026

不同版本对应的不一定是主版本,也可能是不同版本吧
先改了,可以后续维基人讨论

@Sai
Copy link
Copy Markdown
Member

Sai commented May 8, 2026

不同版本对应的不一定是主版本,也可能是不同版本吧 先改了,可以后续维基人讨论

这个不能乱改,主版本是特殊逻辑。

@inchei
Copy link
Copy Markdown
Author

inchei commented May 10, 2026

@Sai @trim21 看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants