【问题标题】:node sequelize - select with null value节点续集 - 选择空值
【发布时间】:2020-08-19 13:59:12
【问题描述】:
var where = {
  [Op.or]:
      [
          { status: { [Op.ne]: 'disable' } },
          { status: { [Op.eq]: null } }
      ],
}

db.diagnostic.findAll({ where: where }).then(resp => {
  res.send(resp)
})

上面的代码正在运行
但是,

var where = {
  status: { [Op.ne]: 'disable' } // I want use only this code instead of `or`
}

db.diagnostic.findAll({ where: where }).then(resp => {
  res.send(resp)
})

我只想使用status: { [Op.ne]: 'disable' }

【问题讨论】:

  • 出了什么问题?在第二种情况下,您将在 SQL 中得到类似:(title ilike '%seach_value%' OR ...) AND status 'disable'。这不是你想要达到的吗?
  • 我不明白你到底想要达到什么目的

标签: sql node.js sequelize.js where-clause


【解决方案1】:

型号:diagnostic.js

...
    status: {
      type: DataTypes.STRING,
      defaultValue: "enable", // <-  default value will solve my problem
    }
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 2021-08-15
    • 2017-05-01
    • 1970-01-01
    相关资源
    最近更新 更多