【发布时间】:2020-05-04 20:37:57
【问题描述】:
上下文 我有用户集合和食谱集合,它们之间的多对多关系
我是这个框架的新手,想知道如何进行以下查询: 计算至少有一个食谱的用户 统计没有任何食谱的用户
我发现loadRelationCountAndMap 在计算用户拥有多少食谱方面非常有用,但我似乎无法根据此属性过滤总响应。
我试过这个:
const users_without_recipes = await getRepository(User)
.createQueryBuilder('user')
.addSelect(['user.createdAt', 'user.email'])
.loadRelationCountAndMap('user.recipes_count', 'user.recipes')
.where('user.recipes_count = :count', {count: 0})
.getManyAndCount();
也尝试使用 postgres array_count 但不确定如何将其与 typeORM 框架集成
非常感谢您的帮助
【问题讨论】:
标签: postgresql typeorm