balderdashy/sails

how to negate (NOT clause) the startsWith operator

Open

#6 990 ouverte le 10 mai 2020

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)JavaScript (22 778 stars) (1 953 forks)batch import
help wantedhelpful info or workaroundmysqlormpr welcome

Description

Node version: 13.12.0 Sails version (sails): 1.2.4 ORM hook version (sails-hook-orm): 2.1.1 DB adapter & version : sails-sql (0.1.0-6) Database engine: MySQL 5.7

SELECT * FROM TABLE WHERE TIPOLOGIA NOT LIKE 'someString%'

So i'm trying with the following criteria but doesn't seem to work:

let rows = await MyModel.find({
    where: {
        TIPOLOGIA: {'!=': {startsWith: 'image/'}}
    }
});

This is the error i'm obtaining:

Could not use the provided `where` clause.  Could not filter by `TIPOLOGIA`: Invalid `!=` ("not equal") modifier.  Does not match the declared data type of the corresponding attribute.  1 error validating value: 
 • Specified value (a dictionary: { startsWith: 'image/' }) doesn't match the expected type: 'string'

This is the relevant portion of the Model

module.exports = {
  tableName: 'ATTACHMENTS',
  primaryKey: 'ID',

  attributes: {
    ID: {type: 'number', unique: true, autoIncrement: true},
    TIPOLOGIA: {
      type: "string",
      columnType: 'varchar',
      maxLength: 255,
      required: true
    },
    ALLEGATO_DATE_CREATOR: {type: 'ref', columnType: 'timestamp'},
    DIR: {
      type: "string",
      maxLength: 255,
      allowNull: true
    }
  }
};

Is this a bug or am i missing something ?

Guide contributeur