diff --git a/package.json b/package.json index 74f8286..481869d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shrimp-server", - "version": "0.7.11", + "version": "0.7.12", "description": "Shrimp 框架后端 — 声明式字段驱动的 Node.js 管理后台框架(Express + Mongoose + JWT)", "main": "dist/main/index.js", "types": "dist/main/index.d.ts", diff --git a/src/Shrimp/ShrimpTableModule.ts b/src/Shrimp/ShrimpTableModule.ts index 4b8703e..9dfa870 100644 --- a/src/Shrimp/ShrimpTableModule.ts +++ b/src/Shrimp/ShrimpTableModule.ts @@ -292,7 +292,8 @@ export class ShrimpTableModule = ITableCrudProto private collectOne(f: IFieldConfig, v: any, add: (moduleKey: string, labelKey: string, id: any) => void): void { if (v == null) return if (f.type === "relation" && f.relation) { - ;(Array.isArray(v) ? v : [v]).forEach((id: any) => id != null && add(f.relation!.moduleKey, f.relation!.labelKey, id)) + // 跳过空串:可选 Relation 常存 "",混进 { _id: { $in } } 会让 Mongoose 转 ObjectId 抛 CastError、整页 500。 + ;(Array.isArray(v) ? v : [v]).forEach((id: any) => id != null && id !== "" && add(f.relation!.moduleKey, f.relation!.labelKey, id)) } else if (f.type === ShrimpFieldTypes.Tab && Array.isArray(f.tabs) && typeof v === "object") { const branch = f.tabs.find(t => t.key === v.type) if (branch) for (const c of branch.fields) this.collectOne(c, v[c.key], add) diff --git a/src/forMongo/MongoShrimpCrud.ts b/src/forMongo/MongoShrimpCrud.ts index b69d044..cc7ff29 100644 --- a/src/forMongo/MongoShrimpCrud.ts +++ b/src/forMongo/MongoShrimpCrud.ts @@ -79,10 +79,9 @@ export class MongoShrimpCrud implements ShrimpCrud { const allRefIds = new Set() for (const item of items) { const val = (item as any)[pop.key] - // 跳过空串:可选 Relation 常存 "",混进 { _id: { $in } } 会让 Mongoose 转 ObjectId 抛 CastError、整页 500。 if (Array.isArray(val)) { - val.forEach((id: any) => { if (id != null && id !== "") allRefIds.add(String(id)) }) - } else if (val != null && val !== "") { + val.forEach((id: any) => { if (id != null) allRefIds.add(String(id)) }) + } else if (val != null) { allRefIds.add(String(val)) } }