sequelize, Statement(where) in statement(where) [英] sequelize, Statement(where) in statement(where)

查看:15
本文介绍了sequelize, Statement(where) in statement(where)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 2 个小时来解决一个不是问题的小问题.我正在使用生成的 yeoman Angular-fullstack 应用程序.

I'm trying for 2 hours to resolve a little problem which is not one. I'm on an generated yeoman Angular-fullstack App.

我想用 sequelize 写这段代码:

I want to write this code with sequelize:

SELECT * 
FROM demand 
WHERE city_id NOT IN (
SELECT city_id
FROM demand
WHERE user_id=req.params.user_id)

我还有以下代码,但这不起作用.我只得到 []

I have yet the following code but that doesn't work. I get only []

export function getCity(req, res) {
  return Demand.findAll({
    where: {
      city_id:{ $notIn: Demand.findAll({
        attributes: ['city_id'],
        where: {
          user_id: req.params.user_id,
        }
      })}
    }
  })
  .then(handleEntityNotFound(res))
  .then(respondWithResult(res))
  .catch(handleError(res));
}

你有线索吗?谢谢.

推荐答案

我没有找到好的解决方案:我终于用查询写了.

I have not found a nice solution: I have finally wrote with query.

export function showDemandArtistNoUser(req, res) {
  return db.sequelize.query('SELECT * FROM demands WHERE city_id NOT IN (SELECT city_id FROM demands WHERE user_id='+req.params.user_id+')', { type: db.sequelize.QueryTypes.SELECT })
  .then(handleEntityNotFound(res))
  .then(respondWithResult(res))
  .catch(handleError(res));
}

而我的 angular-fullstack,我必须在我的页面上添加:

And with my angular-fullstack, i have to add on my page:

 import db from '../../sqldb';

这篇关于sequelize, Statement(where) in statement(where)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆