Count issue with related models using though model
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Steps to reproduce
Create a model called Book with the properties id,author,title
Add a hasMany relation between the default User model and the Book model using a through Model called UserToBook which has the following properties: userId,bookId
The relation is defined in the User model like so.
"books": {
"type": "hasMany",
"model": "Book",
"foreignKey": "userId",
"through": "UserToBook",
"keyThrough": "bookId"
},
Current Behavior
Querying the user for his books using a where filter works as expected (there is a bug there as well which I will address in a different issue). The reason it works is the related function
https://github.com/strongloop/loopback-datasource-juggler/blob/d54d76947724d75a0f46b151c064742c678b0bbe/lib/scope.js#L61
Which, after querying the through model, also queries the related model directly.
When trying to count the number of books of a user, using a where filter (on the author for example), the result is the entire number of books the user has and not the number of books from that author. The reason for that is that the count function
https://github.com/strongloop/loopback-datasource-juggler/blob/d54d76947724d75a0f46b151c064742c678b0bbe/lib/scope.js#L509-L528
Only queries the though model, and not the related model directly.
Expected Behavior
Return the actual count, taking the filter under account
Link to reproduction sandbox
Working on it
Additional information
It seems that the findOne,updateAll and destroyAll suffer from the same issue
- 主要语言
- JavaScript
- 星标
- 279
- 派生
- 362
- 平均合并
- 21 小时 14 分钟
- 30 天内合并 PR
- 16
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
loopbackio/loopback-datasource-juggler 的其他 Issue
-
Breaking changes for `loopback-datasource-juggler@7` not listed anywhere可能重新可做 @dhmlau 于 158 天前认领,目前没有进行中的 PR。 未关闭bug
loopbackio/loopback-datasource-juggler#2548 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
loopbackio/loopback-datasource-juggler#2530 ·
维护者通常 1 天内回复
-
allow empty array in createAll可能已有人在做 @ajay-prajapati07 于 533 天前认领。 未关闭feature
难度 3/5 1-2 天 新手友好度 45/100
loopbackio/loopback-datasource-juggler#2409 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 25/100
loopbackio/loopback-datasource-juggler#2319 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 55/100
loopbackio/loopback-datasource-juggler#1968 ·
维护者通常 1 天内回复
查看 loopbackio/loopback-datasource-juggler 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 63/100
anothaDev/luci-theme-vantage#143 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
kingcharleslzy-ai/dsh-purge#282 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
-
a-corriger bug
难度 2/5 1-3 小时 新手友好度 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复