mysql - TypeORM 使用 ManyToOne 字段和 String 字段创建唯一约束
问题描述
我有以下两个模型:
模型1.ts
@Entity()
export class Model1 {
/**
* Unique identifier
*/
@PrimaryColumn()
id: string = guid();
/**
* Label to use in the UI
*/
@Column({
nullable: true,
})
label?: string;
@ManyToOne(type => Model2, model2 => model2.model1)
model2: Model2;
}
模型2.ts
@Entity()
export class Model2 {
@PrimaryColumn()
id: string = guid();
@Column()
somename: string;
@OneToMany(type => Model1, model1 => model1.model2, {
cascade: true,
})
model1: Model1[];
}
鉴于以上两个实体,我想在 Model 1 表中以 (label, model2.id) 的形式创建一个唯一约束
我尝试搜索多个文档,但找不到解决方案。有没有办法可以使用 TypeORM 做到这一点?
解决方案
推荐阅读
- postgresql - 为什么交叉表查询返回多行而不是一行?
- javascript - 无法通过其默认构造函数动态实例化我的自定义元素
- amazon-cloudwatch - 将事件从一个 CloudWatch 日志流传输到另一个
- python - read_excel vs read_csv:object-dtype 列行为
- r - 将字符添加到列中的重复行
- xcode - 防止接口名称在 OSX 包中公开
- node.js - node js中是否有任何地址验证api?
- python - 通过操作系统限制 Environment.yml 依赖项
- nfc - NFC 读取器 ACR122U 和 libnfc.driver.acr122_usb 无法写入 USB(结果太大)
- development-environment - wix 中的库存检查器 api