【发布时间】:2019-06-14 01:43:18
【问题描述】:
我用 NestJS 和 ORM TypeORM 做一个 API
我有实体:
用户
关系类型
UserRelationshipType(带有用户和关系类型 ForeignKey)
和关系(使用 userRelationshipType ForeignKey)
并且需要查找所有关系,但来自特定用户 所以我需要在某个地方声明“user.id = id”
我已经用 createQueryBuilder 做到了
this.repo
.createQueryBuilder('relationship')
.innerJoinAndSelect(
'relationship.userRelationshipType',
'userRelationshipType',
)
.innerJoinAndSelect(
'userRelationshipType.user',
'user',
'user.id = :id',
{ id: id },
)
.innerJoinAndSelect(
'userRelationshipType.relationshipType',
'relationshipType',
)
.getMany()
而且它的工作 但我不高兴,因为我想用 .find 或 findOne 完成我的所有请求
当我在做的时候
this.repo.find({
relations: [
'userRelationshipType',
'userRelationshipType.user',
'userRelationshipType.relationshipType',
],
where: {userRelationshipType: {user: {id: id}}}
});
那行不通...但是在文档中说要这样做... 我可以找到所有,但可以应用良好的 where 条件(或 join 条件) 你有什么想法吗?
我也尝试过加入,但我有点迷茫
谢谢:)
【问题讨论】:
-
您目前无法按关系过滤,请参阅github.com/typeorm/typeorm/issues/3890
标签: typeorm