Count issue with related models using though model
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- JavaScript
- Star
- 279
- Fork
- 362
- Merge trung bình
- 21 giờ 14 phút
- Pull request đã merge (30 ngày)
- 16
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của loopbackio/loopback-datasource-juggler
-
Breaking changes for `loopback-datasource-juggler@7` not listed anywhereCó thể làm lại được @dhmlau đã nhận 158 ngày trước và không có pull request nào đang mở. Đang mởbug
loopbackio/loopback-datasource-juggler#2548 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Replace deprecated util._extend with Object.assign to ensure compatibility with modern Node.jsĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
loopbackio/loopback-datasource-juggler#2530 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
allow empty array in createAllCó thể đã có người làm @ajay-prajapati07 đã nhận 533 ngày trước. Đang mởfeature
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
loopbackio/loopback-datasource-juggler#2409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
loopbackio/loopback-datasource-juggler#2319 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
loopbackio/loopback-datasource-juggler#1968 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của loopbackio/loopback-datasource-juggler
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
anothaDev/luci-theme-vantage#143 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
kingcharleslzy-ai/dsh-purge#282 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
a-corriger bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày