loopbackio / loopbackio/loopback-datasource-juggler
Count issue with related models using though model
@regevbr がすでに取り組んでいます。
2020年1月21日 から。
- 主要言語
- JavaScript
- スター
- 282
- フォーク
- 366
- 平均マージ
- 17時間 4分
- マージ済み PR(30日)
- 10
説明
## 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.
```json
"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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。