2016-11-03 51 views
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.usrban發現一切消息。我有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) 
    }) 
}) 

回答

0

的方式是寫一個原始的SQL查詢,@mhansen(庫維護者)說。

enter image description here