以下不起作用,其中Group
和User
模型具有N:M关系:
var user_list = ["bob", "alice", "carol"];
Group.find({ where: { id: 1 }, include: [ { model: User, as: 'users' }]).then(function(group) {
// Find group users that are also in user_list
group.users.findAll({ where: { name: user_list }).then(function(affectedRows) {
// Do stuff with affectedRows
});
// Find group users not in user_list
group.users.findAll({ where: { name: { not: user_list } } }).then(function(affectedRows) {
// Do stuff with affectedRows
});
});
错误是:
可能未处理的TypeError:Object [object SequelizeInstance],[对象SequelizeInstance],[对象 SequelizeInstance],[对象SequelizeInstance],[对象 SequelizeInstance],[对象SequelizeInstance],[对象 SequelizeInstance],[对象SequelizeInstance],[对象 SequelizeInstance],[对象SequelizeInstance],[对象 SequelizeInstance],[对象SequelizeInstance]没有方法'findAll'
我正在尝试根据给定列表获取UNION和EXCEPT。有没有办法在不使Sequelize使用原始SQL的情况下执行此操作?