admin管理员组文章数量:1318335
I have a Sequelize model called Staff
. On it there's an array field described as follows:
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)
},
});
I'm trying to create a GraphQL end point which serves up all staff which don't have 'instructor' in their roles
field.
I've read this page of the docs, suggesting that I use a bination of Sequelize.Op
. So I created this:
return Staff.findAll({
where: {
roles: {
[Sequelize.Op.not]: {[Sequelize.Op.contains]: ['instructor']},
}
}
}
)
The above throws the error:
"message": "values.map is not a function"
However, if I am to try a query which isn't a bo such as:
return models.Staff.findAll({
where: {
roles: {
[Sequelize.Op.contains]: ['instructor']
}
}
}
)
The query runs properly, this leads me to believe I perhaps have a syntax error or misunderstanding of how Op
logic is bined.
I have a Sequelize model called Staff
. On it there's an array field described as follows:
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)
},
});
I'm trying to create a GraphQL end point which serves up all staff which don't have 'instructor' in their roles
field.
I've read this page of the docs, suggesting that I use a bination of Sequelize.Op
. So I created this:
return Staff.findAll({
where: {
roles: {
[Sequelize.Op.not]: {[Sequelize.Op.contains]: ['instructor']},
}
}
}
)
The above throws the error:
"message": "values.map is not a function"
However, if I am to try a query which isn't a bo such as:
return models.Staff.findAll({
where: {
roles: {
[Sequelize.Op.contains]: ['instructor']
}
}
}
)
The query runs properly, this leads me to believe I perhaps have a syntax error or misunderstanding of how Op
logic is bined.
- This was reported on GitHub here: github./sequelize/sequelize/issues/9338 - was closed as an issue because it was stale, would be great to get a fix. – BML91 Commented Oct 24, 2018 at 15:22
2 Answers
Reset to default 6Try this:
return models.Staff.findAll({
where: {
$not: {
roles: {
$contains: ['instructor'],
},
},
},
})
The clause $not
need to be prior than the column you target.
This worked just fine for me:
return models.Staff.findAll({
where: {
[Sequelize.Op.not]: {
roles: {
[Sequelize.Op.contains]: ['instructor'],
},
},
},
})
Sequelize.Op.not
have to e before the column that's being reffered to.
本文标签: javascriptSequelizedoes not contain a string within a PostgreSQL array queryStack Overflow
版权声明:本文标题:javascript - Sequelize - does not contain a string within a PostgreSQL array query - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742041778a2417581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论