Skip to content

Commit

Permalink
fix(mis-server): 修改cascade属性 (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tongchong authored Jan 31, 2024
2 parents 9dda13c + 448f6bf commit b696fe1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-readers-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-server": patch
---

之前升级 mikroORM 时 cascade: [Cascade.ALL]属性会在删除 UserAccount 时把 User 和 Account 也删掉
4 changes: 2 additions & 2 deletions apps/mis-server/src/entities/StorageQuota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<User>;

@Property()
Expand Down
6 changes: 3 additions & 3 deletions apps/mis-server/src/entities/UserAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<User>;

@ManyToOne(() => Account, { cascade: [Cascade.ALL], ref: true, nullable: false })
@ManyToOne(() => Account, { deleteRule: "cascade", ref: true, nullable: false })
account: Ref<Account>;

@Property({ columnType: "varchar(10)", comment: Object.values(UserStatus).join(", ") })
Expand Down

0 comments on commit b696fe1

Please sign in to comment.