Sequelize where 嵌套模型的条件
Sequelize where condition for nested models
我有一个带有注释的数据库,users.Now 我想获取所有注释,其中注释内容 = 某物或 users.name = something.I 可以使用 [=24= 轻松编写此查询] 但无法让它与 sequlizer 一起使用。
Note.findAll({
include: [
{ model: Users, where: { name: 'something' }}
]
})
预期查询是
select * from users,notes where notes.content='something' or users.name='something'
问题是 Note 不在 include 中所以我不能使用
where: {
'$or':{
我的问题是如何使用 sequelize
在嵌套 table 上设置 where with 或 condition
Note.findAll({
where: {
[Op.or]: [
{ content: { [Op.like]: 'something' } },
{ '$users.name$': { [Op.like]: 'john' } },
]
},
include: [
{ model: Users, as: 'users', required: true }
]
})
我有一个带有注释的数据库,users.Now 我想获取所有注释,其中注释内容 = 某物或 users.name = something.I 可以使用 [=24= 轻松编写此查询] 但无法让它与 sequlizer 一起使用。
Note.findAll({
include: [
{ model: Users, where: { name: 'something' }}
]
})
预期查询是
select * from users,notes where notes.content='something' or users.name='something'
问题是 Note 不在 include 中所以我不能使用
where: {
'$or':{
我的问题是如何使用 sequelize
在嵌套 table 上设置 where with 或 conditionNote.findAll({
where: {
[Op.or]: [
{ content: { [Op.like]: 'something' } },
{ '$users.name$': { [Op.like]: 'john' } },
]
},
include: [
{ model: Users, as: 'users', required: true }
]
})