【问题标题】:How can i use not or != in nestjs我如何在 nestjs 中使用 not 或 !=
【发布时间】:2023-02-02 17:42:24
【问题描述】:

我想比较两个孩子,一个是相关的,另一个是我在查询中给出的,并获取所有信息,例如:

async getAllPhoto(id: string) {
var photo = await this._photoRepository.find({
      relations: {
        catalogue: true,
      },
      where: { catalogue: { id: Not(id) } },
    });
    return photo;
}

我试过了但是得到了一个空数组。

【问题讨论】:

  • 您是否尝试记录 find() 方法返回的内容?如果它给出一个空数组,则可能意味着数据库中没有与具有给定 id 的目录无关的照片,或者您可以检查数据库中的数据是否有匹配的照片和目录你的标准

标签: node.js postgresql nestjs typeorm


【解决方案1】:
const ids = 2; // get your id which you request from font-end
const photo = this.repository.find({
  relations:['catalogue'],
  where:{
    catalogue:{
      id: Not(ids)
    }
  }
})

当你在 nestjs 中开发项目时,

你最好在你的数据库配置中启用 "logging":true !

你会发现所有来自 ORM 的原始 sql。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 2021-06-28
    • 2021-12-31
    • 2020-07-23
    • 2019-09-15
    相关资源
    最近更新 更多