【发布时间】:2019-03-28 00:43:26
【问题描述】:
我有一个名为Staff 的 Sequelize 模型。上面有一个数组字段,描述如下:
const Staff = sequelize.define("staff", {
name: {
type: DataTypes.STRING,
},
email: {
type: DataTypes.STRING,
unique: true
},
password: {
type: DataTypes.STRING,
},
roles: {
type: DataTypes.ARRAY(DataTypes.STRING)
},
});
我正在尝试创建一个 GraphQL 端点,为所有在其roles 字段中没有“讲师”的员工提供服务。
我读过this page of the docs,建议我使用Sequelize.Op 的组合。所以我创建了这个:
return Staff.findAll({
where: {
roles: {
[Sequelize.Op.not]: {[Sequelize.Op.contains]: ['instructor']},
}
}
}
)
上面抛出错误:
"message": "values.map is not a function"
但是,如果我要尝试不是组合的查询,例如:
return models.Staff.findAll({
where: {
roles: {
[Sequelize.Op.contains]: ['instructor']
}
}
}
)
查询运行正常,这让我相信我可能对Op 逻辑的组合方式有语法错误或误解。
【问题讨论】:
-
这是在 GitHub 上报告的:github.com/sequelize/sequelize/issues/9338 - 已作为一个问题关闭,因为它已过时,如果能得到修复,那就太好了。
标签: javascript postgresql sequelize.js