'I use mikro-orm (with mongoDB) in my typescript project. How to forbid remove entity if it connected with another entity? Relation manytomany
My entities:
@Entity()
export class AccessUser extends BaseEntity {
@ManyToOne(() => UserName, { onUpdateIntegrity: "no action"})
userName: UserName;
@ManyToMany(() => Right, a => a.accessUsers, {}/*"accessUsers")
rights = new Collection<Right>(this);
.....
}
@Entity()
export class Right extends BaseEntity {
@Property()
right: string;
@ManyToMany(() => AccessUser)
accessUsers = new Collection<AccessUser>(this);
}
export abstract class BaseEntity {
@PrimaryKey()
_id!: ObjectId;
@SerializedPrimaryKey()
id!: string;
@Property()
createdAt = new Date();
@Property({ onUpdate: () => new Date() })
updatedAt = new Date();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
