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)


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01