[英]How to make a subquery in SELECT in TypeORM if there is no such field but an entity?
我嘗試在 TypeORM 中使用子查詢創建查詢。
const query = await this.contactRepository.createQueryBuilder('c')
.select(['c.id', 'c.type_id', 'c.value'])
.addSelect(subQuery => {
return subQuery
.select('system_name', 'type_name')
.from(ContactTypePropsEntity, 'ctp')
.where('ctp.id = c.type_id')
}, 'type_name')
.where('c.entity_id = :entity_id AND c.entity_type = :entity_type AND c.deleted = :deleted', {
entity_id: id,
entity_type: type,
deleted: 0
})
.getMany();
但是“type_name”字段不在 ContactEntity 中。 如何使用來自 ContactEntity 實體的字段從子查詢 output 創建一個字段。
從某處的 where 語句中添加類似這樣的內容。
(qb: SelectQueryBuilder<SomeEntity>) => {
qb.where(`parentQueryEntity.id in ` +
qb.subQuery()
.select('s.id')
.from(SomeEntity, 's')
.getQuery(),
)
}
干杯 M8!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.