postgresql - Postgres leftJoinAndMapMany 使用 TypeORM 查询(属性未定义)
问题描述
我一直在使用 TypeORM 使用 PostgreSQL,但在获取 Follower 表并检查用户是否在该表中时遇到了一些问题。
这是我的代码:
// queryTest.ts
data = await getRepository(User)
.createQueryBuilder('user')
.leftJoinAndMapMany('user.id', Post, 'post', 'post.userId = user.id')
.leftJoinAndMapMany('post.id', Follow, 'follow', 'follow.userId = user.id')
// Post author's follower
.where(new Brackets(qb => {
qb.where('post.publicScope = :follower', { follower: 'Follower' })
.andWhere('post.userId = follow.followeeId')
.andWhere(':myId = follow.userId', { myId: user.id })
}))
.getMany()
当我尝试发送这个查询时,我得到{ }
(应该得到一些用户、帖子、关注者数据)
我有User
, Post
,Follow
实体,我正在尝试获取这些数据:
我的追随者的帖子,他设置为“追随者”(假设我正在追随某个名人,他发布了仅针对追随者的内容,而我正在尝试获取该数据)
或者我也在考虑具有 ManyToMany 关系的 makig 2 个实体(Follower、Followee)。任何机构都可以帮我解决这个问题吗?
解决方案
推荐阅读
- python - 熊猫数据框中的列总和
- php - 如何动态反转引导列?
- icalendar - 通过 METHOD:PUBLISH 结合 SEQUENCE 发布频繁更改的 iCalendar
- java - 使用 spring-data-jpa 保存新条目
- c - 函数 'func_dbl_arr_calloc' 在 C99 中无效
- wpf - WPF VB DataGridCombox DataGridRow
- javascript - Reactjs 中偶数/奇数 div 的样式
- django - 如何在用户输入信息时更改 django 表单
- typescript - 我可以为以编程方式生成的 TypeScript 接口/类型的键添加前缀或后缀吗?
- regex - 无法从正则表达式中的 URL 路径中提取动态值