CREATE TABLE msg (usr INTEGER, txt TEXT);
CREATE TABLE ban (usr INTEGER);
SELECT * FROM msg WHERE (msg.usr NOT IN (SELECT usr FROM ban));
如果在msg
中找不到msg.usr
,那么普通SQL中的单行将从ban
中选择所有内容。我Sequelize query docs打开了,但找不到Sequelize的做法是什么?
在这里,我已经能够从被禁止的用户那里获取消息,但无法反转结果:
var Msg = sequelize.define('Msg', {
usr: { type: Sequelize.INTEGER, primaryKey: true },
txt: Sequelize.STRING
}, {
tableName: 'msg'
});
var Ban = sequelize.define('Ban', {
}, {
tableName: 'ban'
});
Msg.hasMany(Ban);
Ban.belongsTo(Msg);
Msg.findAll({
include: [{
model: Ban,
where: { MsgUsr: {$ne: null} }
}]
}).then((a)=>{
a.forEach((row)=>{
let ban = '-'
if(row.Bans[0]) ban = row.Bans[0].id
console.log(row.usr, row.txt, ban)
})
})