Ensure unique field value in loopback model

前端 未结 3 650
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 17:29

How to ensure uniqueness of a particular field in loopback model. Like below is the model Post, I have a field genericId in it, I want it to be unique in the database, and l

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 18:02

    The Lookback v4 solution looks like this:

    @model()
    export class Client extends Entity {
    
      @property({
        type: 'string',
        required: true,
        index: {
          unique: true,
        },
      })
      name: string;
    
    }
    

    Then you must update your schema:

    npm run migrate
    

    or recreate it:

    npm run migrate -- --rebuild
    

提交回复
热议问题