balderdashy/sails

how to negate (NOT clause) the startsWith operator

Open

#6.990 aberto em 10 de mai. de 2020

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)JavaScript (1.953 forks)batch import
help wantedhelpful info or workaroundmysqlormpr welcome

Métricas do repositório

Stars
 (22.778 stars)
Métricas de merge de PR
 (Mesclagem média 23h 44m) (1 fundiu PR em 30d)

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 ?

Guia do colaborador