续集,Statement(where)中的Statement(where) [英] sequelize, Statement(where) in statement(where)

查看:140
本文介绍了续集,Statement(where)中的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.

我想用以下代码编写此代码:

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));
}

您有任何线索吗?
谢谢。

Have you a clue? Thank you.

推荐答案

我没有找到一个很好的解决方案:我终于用查询写了信。

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));
}

使用我的角度全栈,我必须在页面上添加:

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

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

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

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