NodeJS 如何在nestjs中使用not或!=

xdnvmnnf  于 2023-02-03  发布在  Node.js
关注(0)|答案(1)|浏览(184)

我想比较一个在relation中的id和我在查询中给出的另一个id,并获得所有信息,例如:

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

我尝试了这个方法,但是得到了一个空数组。

kq4fsx7k

kq4fsx7k1#

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。

相关问题