I've been struggling to make this work for some time and was hoping for some guidance.
OBJECTIVE: I'm attempting to sort the posts by the number of likes they currently have.
CURRENT:
const posts = await db.post.findAll({
include: [ db.user, { model: db.like_post, where: { user_id: user }, required: false } ],
where: { category },
group: [ [ sequelize.col('like_posts.post_id') ] ],
order: [ [ sequelize.fn('count', sequelize.col('like_posts.post_id')), 'DESC' ] ]
});
The error message I'm currently encountering is:
"message": "column \"post.id\" must appear in the GROUP BY clause or be used in an aggregate function",
Does anyone have any advice on what I might be doing incorrectly to achieve the correct post order?
Thank you once again for all the assistance and suggestions.