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)
基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01