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
findAndCount returns array instead of count when the query uses GROUP BY #9109
I am fetching a list of records (User) and counting the number of Projects each is associated with. I am using [sequelize.fn('COUNT', sequelize.col('projects.id')), 'project_count'] together with GROUP BY to do that in a single query without fetching whole project entities.
MySQL: SequelizeDatabaseError: Unknown column 'user.id' in 'field list'
Postgres: SequelizeDatabaseError: missing FROM-clause entry for table "user"
MSSQL: SequelizeDatabaseError: Column 'Users.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Activity
testcase for sequelize#9109
tizzyapunkt commentedon Aug 5, 2018
Currently facing the same issue. Any news on that?
notflip commentedon Dec 4, 2018
Any news on this?
keyiis commentedon Feb 13, 2019
@jharting i facing the same issue. are you fixed?
papb commentedon Jul 30, 2019
@jharting Thanks for the testcase. Sorry to take so long for a response.
I reproduced this in every dialect. Interestingly, every dialect gives a different failure.
AssertionError: expected [ Array(3) ] to equal 3SequelizeDatabaseError: (conn=10, no: 1054, SQLState: 42S22) Unknown column 'user.id' in 'field list'SequelizeDatabaseError: Unknown column 'user.id' in 'field list'SequelizeDatabaseError: missing FROM-clause entry for table "user"SequelizeDatabaseError: Column 'Users.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.jeebus3000 commentedon Jan 10, 2020
Any progress on this?
papb commentedon Jan 17, 2020
@jeebus3000 none that I know of
bentedder commentedon Jul 12, 2020
Is there still no resolution on this?
Hwan-seok commentedon Sep 7, 2020
Still... :(
RahulRawat1994 commentedon Sep 30, 2020
Any progress
RahulRawat1994 commentedon Sep 30, 2020
? :(
ritvikroy commentedon Jan 4, 2021
Just use "result.count.length/count.length" instead "result.count/count" when you use Group by in findAndCountAll function.