sequelize 查找空字符串报错

sequelize 查找空字符串报错

需求:找出为""或者为null的行数

错误版本

const count = await Model.count({
      where: {
        $or: [
          { value: null },
          { value: '' },
        ],
      },
    });
sql: SELECT count(*) AS `count` FROM `setting` AS `setting` WHERE ((`setting`.`deleted_at` > '2019-04-16 10:02:39' OR `setting`.`deleted_at` IS NULL) AND (`setting`.`required` = true AND (`setting`.`value` IS NULL OR `setting`.`value` = '\"\"')));

正确版本

const count = await this.app.model.Setting.count({
      where: {
        $or: [
          { value: null },
          literal('value = ""'),
        ],
      },
    });
1 Star2 Stars3 Stars4 Stars5 Stars (尚未评分)
Loading...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注