[英]typeorm querybuilder: select relation of relation only
所以我有这些实体:
Group {
id: number;
name: string;
persons: Person[];
}
Person {
name: string;
items: Item[];
}
Item {
name: string;
active: boolean;
}
我有什么可用的:一组组ID 的groupIds
。
我的目标:要获得一个数组Item
,但只有一个是一组在containt即group.id
是组阵列我也内拥有财产active
true
。
我试图构建一个这样的查询构建器:
this.groupRepository.createQueryBuilder('group')
.innerJoin('group.persons', 'persons')
.innerJoinAndSelect('persons.items', 'items')
.where({'items.active': true, 'group.id': In(groupIds)})
.getMany();
但是我只得到一group
包含有效item
的group
(没有任何关系)。
如果这甚至可以通过单个查询实现,我需要更改什么?
尝试使用这个:
this.groupRepository.createQueryBuilder('group')
.leftJoinAndSelect('group.persons', 'persons')
.leftJoinAndSelect('persons.items', 'items')
.where('items.active =:active', {active: true})
.andWhere('group.id IN (:...groupIds)', {groupIds})
.getMany();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.