0
votes

I've been reading the loobpack's framework documentation but I couldn't find the answer I need.

I would like to know if there is any options to set a property as case insensitive in the database.

I know I can handle this in the front-end of the application, however front-end validations are extremely dangerous as they can be overrided.

I currently have a model with the following content on myModel.json:

{
  "name": "mymodel",
  "properties": {
    "id": {
      "type": "number",
      "required": true
    },
    "code": {
      "type": "string",
      "required": true,
      "index": {
        "unique": true
      }
    },
    "name": {
      "type": "string",
      "required": true
    },
  }
}

The property code has to be unique, however I've tried to insert the word "COD001" and "cod001" and they were both accepted.

1

1 Answers

1
votes

You could use the 'check uniqueness' validation method.

MyModel.validatesUniquenessOf('code', {ignoreCase: false});

Reference: https://apidocs.loopback.io/loopback-datasource-juggler/#validatable-validatesuniquenessof