javascript - 如何通过ID从数据库中获取对象
问题描述
就我而言,我在我的请求中接受了一个 id 列表,例如,如何使用and[1,2,3]
仅从我的数据库中获取具有此 id 的对象?typeorm
querybuilder
我试试这个:
if(dto.customersIds){
Array.prototype.forEach.call(dto.customersIds, ids => {
res.where(`customer.id = ${ids}`);
})
}
但这不起作用,让我只得到数组中最后一个 id 的对象。
有人可以告诉我如何通过 id 获取对象吗?
谢谢你的帮助
解决方案
代替:
Array.prototype.forEach.call(dto.customersIds, ids => {
res.where(`customer.id = ${ids}`);
})
和:
res.whereInIds(dto.customersIds);
我假设res
是从createQueryBuilder
推荐阅读
- xml - xsd:扩展不起作用:src-resolve:无法将名称“BaseObj”解析为(n)“类型定义”组件
- actions-on-google - 获取注册设备 Google Homegraph
- view - 无法使用不同于创建视图的库名读取 SAS 视图
- python - Python script with executable permission says "Command Not Found"
- java - JavaFX creates Alert dialog which is too small
- python - 当我导入模块时,它运行整个 python 文件
- mysql - Clean multiple numbered mysql tables
- c# - 由于混合 AcroForm-XFA 问题,在 C# 中使用 itext7 进行的 AcroField 更改未提交/不可见
- html - Can not place 2 tables side-to-side
- python-3.x - 如何将聊天机器人问题及其答案添加到 pandas 数据框中,以便以后在提出相同问题时可以检索到它