'blocked' 表有两列,'userId' 和 'messageId',它是表 'messages' 的外键。
我想在过滤被阻止的消息后获取消息。我试过这个:
messages.findAll({
where: {
userId,
},
include:[{
model: 'blocked',
required: false
attributes:[],
where: {
userId,
},
}],
});
没用。有人可以提出解决方案吗?
最佳答案
我会将其分为两个查询
const blocked = await blocked.findAll({
where: {
userId,
attributes: ['messageId']
}
});
const blockedIds = blocked.map(b => b.messageId);
const messages = await messages.findAll({
where: {
id: { $notIn: blockedIds }
}
});
关于sequelize.js - 如何从列中获取行,不包括某些行,这些行的 Id 保存在另一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58040901/