查询子模型时如何获取 HasMany 关系中的计数值?



在我创建的类别模型上,我有以下关系:

"subscriptions": 
{ 
"type": "hasMany", 
"model": "Subscription" 
"foreignKey": "",
"options": { "nestRemoting": true } } }

运行时如何获得 Count(( 结果:

this.userService.getCategories(this.currentUser.id, 
{include: {relation: 'subscriptions', scope: {type: 'count'}}})
.subscribe((data: any[]) => { this.categories = data };

我想在同一个 observable(( 中获取属于用户的类别时计算订阅数量。

就像上面显示的那样,我尝试使用"计数"类型的范围。 什么也没来。

感谢您的任何帮助。

作为答案: 环回提供"包含"筛选器,以便能够检索相关模型。 因此,将检索可观察量。它确实包含关系。 获取 Count(( 就像在 HTML 中编写{{category.subscriptions.length}}一样简单。

希望这有帮助。

最新更新