【发布时间】:2020-02-21 16:13:34
【问题描述】:
我正在构建一个后端微服务,它使用 postgres 作为 DB 和 TypeORM (NodeJs) 库来管理与它的连接。
假设我的数据库包含 3 个表/实体。
- 用户表(主列是-id)
- Profile 表(主列 id,然后外键 user_id 指向用户表 id 列) 可能有多个个人资料行与一位用户相关联
- 经验表(主列id,然后外键profile_id列指向profile表id列) 可能有多个体验行与一份个人资料相关联
a) 我可以执行一个复杂的查询来获取配置文件行和与之关联的所有经验行吗?
getFullProfile(profileId: number) {
return this.profileEntityRepository.createQueryBuilder('profile')
.where('profile.id = :profileId', { profileId })
.innerJoinAndMapMany('profile.experience', ExperienceEntity, 'experience', 'experience.id = profile.id')
.getOne();
}
遗憾的是,这不会返回任何结果(如果我注释掉 innerJoinAndMapMany 行,它会返回)。
有什么建议吗?它不必是基于 TypeORM api 的答案,简单的普通查询就足够了。
谢谢!
【问题讨论】:
标签: postgresql typeorm