0
CREATE TABLE msg (usr INTEGER, txt TEXT);
CREATE TABLE ban (usr INTEGER);
SELECT * FROM msg WHERE (msg.usr NOT IN (SELECT usr FROM ban));
這一個班輪在普通的SQL會選擇msg
如果msg.usr
不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)
})
})