You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
findAndCountAll returns correct count but incorrect number of rows with query into association #9940
We expect a count of 1 and there to be 1 row returned
What is actually happening?
We get back a count of 1, with 2 rows.
I increased the amount of data into our dev environment, and it looks like the count is getting the correct query, but the data returned back looks like the query was ignored
It seemed to work as I had an "activity" model includes that had many rows itself and when the parent model count would be seven, only one row would be returned holding the 71 rows of activity included. Making subquery false, returns all seven rows as expected.
Reacted by kwikman, Soso966 and Alexander Pirozhkov
I made subquery false in my pagination function @scottmay2020 I don't know what exactly the subQuery field does (will have a look later) but this solved the same issue described here. I tried almost the whole day. Thanks!
Using subQuery: false doesnt work when I have left join + limit. Basicaly the limit should be applied on the original model before left joining but it is being applied on the whole joined result set. It works perfectly in findAll with subQuery: false but not findAndCountAll
Activity
doc82 commentedon Oct 9, 2018
Looks like this is happening with any where statements attached to an included association :(
doc82 commentedon Oct 15, 2018
Found out the issue: if I do a query into an association with a limit + offset it breaks. If I remove the limit and offset it works great
NaifousBS commentedon Oct 24, 2018
webindustry54 commentedon Nov 7, 2018
doc82 commentedon Feb 7, 2019
scottmay2020 commentedon Nov 27, 2019
I made subquery false in my pagination function:
const paginate = (query, { page, pageSize }) => { const currentPage = parseInt(page, 10) - 1 || 0; const currentPageSize = parseInt(pageSize, 10) || 25; const offset = currentPage * currentPageSize; const limit = offset + currentPageSize; return { ...query, offset, limit, // subQuery: false, }; };It seemed to work as I had an "activity" model includes that had many rows itself and when the parent model count would be seven, only one row would be returned holding the 71 rows of activity included. Making subquery false, returns all seven rows as expected.
spinlud commentedon Jan 9, 2020
Same issue:
alikhanoitan commentedon Jan 26, 2022
rodrigorodriguez commentedon Dec 15, 2023
@othonlima.
jajo-shubham commentedon Sep 2, 2025
Using
subQuery: falsedoesnt work when I have left join + limit. Basicaly the limit should be applied on the original model before left joining but it is being applied on the whole joined result set. It works perfectly infindAllwithsubQuery: falsebut notfindAndCountAll