Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何按包含的模型筛选结果?_Sql_Node.js_Sequelize.js - Fatal编程技术网

Sql 如何按包含的模型筛选结果?

Sql 如何按包含的模型筛选结果?,sql,node.js,sequelize.js,Sql,Node.js,Sequelize.js,我在使用sequelize查询过滤结果时遇到了一个问题,描述如下 用户模型: var User = db.define('User', { email: { type: types.STRING, unique: true }, password: { type: types.STRING }, firstName: { type: types.STRING }, lastName: { type: types.STRING

我在使用sequelize查询过滤结果时遇到了一个问题,描述如下

用户模型:

var User = db.define('User', {
  email: {
    type: types.STRING,
    unique: true
  },
  password: {
    type: types.STRING
  },
  firstName: {
    type: types.STRING
  },
  lastName: {
    type: types.STRING
  },
  type: {
    type: types.INTEGER
  }
});
用户服务模型:

var UserServices = db.define('UserServices', {
  service: {
    type: types.INTEGER
  }
});


var Countries = db.define('Countries', {
  name: {
    type: types.STRING
  },
  code: {
    type: types.STRING(10)
  }
});
关系:

User.hasMany(UserServices);
UserServices.belongsTo(User);

Countries.hasMany(User);
User.belongsTo(Countries);
以下问题:如何仅筛选出属于指定国家/地区、具有特定服务和指定用户类型的用户

我现在要做的是(没有按预期工作):


这应该行得通。您应该在operator for Service中使用,这应该可以工作。您应该在operator for service中使用
User.findAll({
  where: {
    type: 3
  },
  inlcude: [{
    model: Countries,
    where: {
      id: 2
    }
  }, {
    model: UserServices,
    where: {
      service: [1, 2, 3]
    }
  }]
}).then((user) => {
...
})