Loopbackjs 查询子模型时,如何获取HasMany关系中的计数值?
在我创建的类别模型上,我有以下关系:Loopbackjs 查询子模型时,如何获取HasMany关系中的计数值?,loopbackjs,Loopbackjs,在我创建的类别模型上,我有以下关系: "subscriptions": { "type": "hasMany", "model": "Subscription" "foreignKey": "", "options": { "nestRemoting": true } } } 运行时如何获得Count()结果: this.userService.getCategories(this.currentUser.id, {include: {relation: 'subscrip
"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”的范围。什么都没有
谢谢您的帮助。作为回答:
环回提供“包含”过滤器,以便能够检索相关模型。
因此,检索到一个可观察的对象。它确实包含了这种关系。
获取Count()非常简单,只需在HTML中编写{{category.subscriptions.length}
希望这有帮助