【发布时间】:2021-07-21 01:37:18
【问题描述】:
我在开发 Web 应用程序时使用了 postgresSQL、Typeorm 和 NestJs。 我有几个实体:
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: string;
@Column()
name: string;
@ManyToMany(
() => Property,
{ nullable: true, eager: true },
)
@JoinTable()
properties: Property[];
}
@Entity()
export class Property {
@PrimaryGeneratedColumn()
id: string;
@Column({ unique: true })
key: string;
@Column()
name: string
}
我正在尝试按属性获取产品。 这在 sql 中给出:
;with r as (
SELECT
bien.*,
ARRAY['usage.toto'::varchar] = array_agg(p.key) as compare1
from bien
INNER JOIN bien_properties_property bpp on bien.id = bpp."bienId"
INNER JOIN property p on p.id = bpp."propertyId"
GROUP BY bien.id
)
select * from r
where compare1
有人可以帮我吗?
谢谢
【问题讨论】:
标签: typescript postgresql nestjs typeorm