WMS_MAIN/association_fix_plan.md
2026-03-23 17:10:07 +08:00

2.1 KiB
Raw Blame History

Association Fix Plan

更新时间: 2026-03-23 适用阶段: Model 重构阶段 4(关联关系规范化)

1. 目标

  • 统一 alias 命名规则(belongsTo/hasOne 用单数,hasMany/belongsToMany 用复数)。
  • 清理重复或冲突关联定义,避免 include 歧义。
  • 保持 system/qimen 输出结构不变,通过 baseline/compare 门禁验证。

2. 已完成修复

2.1 幽灵模型收敛(已完成)

  • 将 AccountStoreRole 相关调用链迁移到 AccountStoreEmployee + EmployeeRole + Role + Store。
  • 覆盖主链路:
    • app/service/systems/store.js
    • app/service/systems/account_platform.js
    • app/service/systems/auth/user.js

2.2 alias 标准化(已完成)

  • 新标准 alias:
    • accountStoreEmployees
    • employeeRoles
  • 已完成调用迁移:
    • account_platform 服务 include 与读取逻辑统一为 employeeRoles
    • auth/user 服务 include 统一为 employeeRoles

2.3 重复关联清理(已完成)

  • 已移除以下重复兼容 alias 定义:
    • Account.accountStoreRoles
    • AccountStoreEmployee.employeeRole
    • Role.employeeRole
    • Store.accountStoreEmployee
  • 保留必要单数 alias(belongsTo 语义):
    • AccountPlatformActive.accountStoreEmployee

3. 验证策略

每批改动执行以下门禁:

  1. node .\script\method-output-regression.cjs baseline 8
  2. node .\script\method-output-regression.cjs compare
  3. node .\script\tmp-generate-method-regression-test.cjs
  4. npx egg-bin test temp/generated-tests/system.method-output.generated.test.js
  5. npx egg-bin test test/app/controller/system.user.login.test.js test/app/controller/system.user.info.test.js test/app/controller/home.test.js

4. 当前状态

  • 输出一致性门禁:通过(mismatch=0)。
  • 关键冒烟测试:通过。
  • 对外 API 参数/返回:无结构变更。

5. 剩余工作

  • 全量扫描其余模型类方法中的 include alias 一致性(已完成,差集扫描异常项 0 个)。
  • 评估并落地 permission.parent_id 自关联约束策略(已完成:root 语义归一为 NULL + 自关联 FK)。
  • 进入阶段 5:Model 内部能力清理与边界固化。