Вла*_*лов 17 typescript typeorm
我有两个实体:
@Entity()
export class Point {
@PrimaryGeneratedColumn('uuid')
id: string;
// some other stuff
}
@Entity()
export class Product {
@PrimaryGeneratedColumn('uuid')
id: string;
@IsOptional()
@ManyToMany(() => Point)
@JoinTable()
prohibitedToSaleOn: Point[];
}
Run Code Online (Sandbox Code Playgroud)
我想要获得产品,其中prohibitedToSaleOn(数组Point)中的任何对象都满足条件
point.id != {idWhatIWant}
所以,最后我想获得所有产品,而不是在选定的点禁止销售。我做了这样的事情:
return this.productRepository.createQueryBuilder('product')
.leftJoin('product.prohibitedToSaleOn', 'point')
.where('point.id != :id', {id})
.getMany();
Run Code Online (Sandbox Code Playgroud)
但它不起作用(根本不应该)
我需要有关正确请求的帮助。谢谢=)
PS我使用PostgreSQL
我发现最简单的方法是使用typeorm's NotOperator,如下所示:
return this.productRepository.find( { where: id: Not('some_id') } );
Run Code Online (Sandbox Code Playgroud)
有关以下内容的文档Not:
查找选项运算符。用于否定表达式。示例: { title: not("hello") } 将返回 title 不等于“hello”的实体。
在这里阅读更多内容
| 归档时间: |
|
| 查看次数: |
57339 次 |
| 最近记录: |