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
I was not able to find a way to run a sum on an include. The special use case here would be a posts table with a separate votings table from which I need only the sum of upvotes/downvotes. If that's already possible without running raw queries, it would probably be worth adding to the wiki.
Am I missing something @dongseok0? The example you give doesn't work for me, I get "'Column 'Model.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".
As soon as I add an 'include' array, Sequelize automatically Model.id to the SELECT (as noted in #3920, because it's the primary key) and this breaks the aggregation. See
Activity
mickhansen commentedon Oct 17, 2014
Can you show the include you are using?
You can change the attributes loaded with something like:
dongseok0 commentedon May 26, 2015
I have same question like below :
It seems include is not supported by sum method?
Anyways, I managed to get same result by using your attributes example, but it would be nice include supported by aggregate or sum method.
janmeier commentedon May 26, 2015
@dongseok0 Can you provide some more context? What do your models and associations look like, and which column do you want to sum on?
dongseok0 commentedon May 28, 2015
Association:
And I want the 'point' column from Model. Currently I'm doing below:
pimterry commentedon Jun 24, 2015
Am I missing something @dongseok0? The example you give doesn't work for me, I get "'Column 'Model.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".
As soon as I add an 'include' array, Sequelize automatically Model.id to the SELECT (as noted in #3920, because it's the primary key) and this breaks the aggregation. See
sequelize/lib/model.js
Line 1176 in 2c4a9f3
dongseok0 commentedon Jun 25, 2015
@pimterry - Yeah, above example is currently working on our production.
Do you have any problems if you just find instead of using fn?