sequelize, Statement(where) in statement(where)(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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sequelize, Statement(where) in statement(where)


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01