balderdashy/sails

how to negate (NOT clause) the startsWith operator

Aperta

#6990 aperta il 10 mag 2020

 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (1953 fork)batch import
help wantedhelpful info or workaroundmysqlormpr welcome

Metriche repository

Star
 (22.778 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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 ?

Guida contributor