【发布时间】:2022-04-14 20:05:39
【问题描述】:
我的项目中有一个Department 模型。属性为id、name。 name 当然应该是独一无二的。但是我似乎看不到设置在哪里,所以我可以放一些类似
@model()
export class Department extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'string',
required: true,
unique: true // ---> This is what I want. But how?
})
name: string;
constructor(data?: Partial<Department>) {
super(data);
}
}
我尝试挖掘到Model 文档,似乎我可以用@model 装饰器做一些事情。但是我没有找到关于它的文档。
另外,我想在 PostgreSQL 中作为数据源执行此操作。有什么线索吗?任何建议将不胜感激。
【问题讨论】:
-
我不确定如何将其设置为副本,但答案就在这里,Ensure unique field value in loopback model
标签: loopbackjs strongloop loopback4