balderdashy/sails

how to negate (NOT clause) the startsWith operator

Open

#6,990 创建于 2020年5月10日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)JavaScript (22,778 star) (1,953 fork)batch import
help wantedhelpful info or workaroundmysqlormpr welcome

描述

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 ?

贡献者指南