From 448f6bf80953848c7d69ea262f8d72c58038804d Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Wed, 31 Jan 2024 03:02:33 +0000 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9cascade=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/two-readers-think.md | 5 +++++ apps/mis-server/src/entities/StorageQuota.ts | 4 ++-- apps/mis-server/src/entities/UserAccount.ts | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/two-readers-think.md diff --git a/.changeset/two-readers-think.md b/.changeset/two-readers-think.md new file mode 100644 index 0000000000..16b80d339b --- /dev/null +++ b/.changeset/two-readers-think.md @@ -0,0 +1,5 @@ +--- +"@scow/mis-server": patch +--- + +之前升级 mikroORM 时 cascade: [Cascade.ALL]属性会在删除 UserAccount 时把 User 和 Account 也删掉 diff --git a/apps/mis-server/src/entities/StorageQuota.ts b/apps/mis-server/src/entities/StorageQuota.ts index 4d464e6af4..a9224684bf 100644 --- a/apps/mis-server/src/entities/StorageQuota.ts +++ b/apps/mis-server/src/entities/StorageQuota.ts @@ -10,7 +10,7 @@ * See the Mulan PSL v2 for more details. */ -import { Cascade, Entity, ManyToOne, PrimaryKey, Property, Ref } from +import { Entity, ManyToOne, PrimaryKey, Property, Ref } from "@mikro-orm/core"; import { User } from "src/entities/User"; import { EntityOrRef, toRef } from "src/utils/orm"; @@ -20,7 +20,7 @@ export class StorageQuota { @PrimaryKey() id!: number; - @ManyToOne(() => User, { cascade: [Cascade.ALL], ref: true, nullable: false }) + @ManyToOne(() => User, { deleteRule: "cascade", ref: true, nullable: false }) user: Ref; @Property() diff --git a/apps/mis-server/src/entities/UserAccount.ts b/apps/mis-server/src/entities/UserAccount.ts index 9ba6ca7d43..232e4e8034 100644 --- a/apps/mis-server/src/entities/UserAccount.ts +++ b/apps/mis-server/src/entities/UserAccount.ts @@ -10,7 +10,7 @@ * See the Mulan PSL v2 for more details. */ -import { Cascade, Entity, ManyToOne, PrimaryKey, Property, Ref } from "@mikro-orm/core"; +import { Entity, ManyToOne, PrimaryKey, Property, Ref } from "@mikro-orm/core"; import { Decimal } from "@scow/lib-decimal"; import { Account } from "src/entities/Account"; import { User } from "src/entities/User"; @@ -33,10 +33,10 @@ export class UserAccount { @PrimaryKey() id!: number; - @ManyToOne(() => User, { cascade: [Cascade.ALL], ref: true, nullable: false }) + @ManyToOne(() => User, { deleteRule: "cascade", ref: true, nullable: false }) user: Ref; - @ManyToOne(() => Account, { cascade: [Cascade.ALL], ref: true, nullable: false }) + @ManyToOne(() => Account, { deleteRule: "cascade", ref: true, nullable: false }) account: Ref; @Property({ columnType: "varchar(10)", comment: Object.values(UserStatus).join(", ") })