我一直試圖讓它工作一段時間,并希望獲得一些見解。目標:我正在嘗試根據他們目前擁有的喜歡數量對帖子進行排序。當前的: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' ] ]});我目前收到的錯誤是:"message": "column \"post.id\" must appear in the GROUP BY clause or be used in an aggregate function",為了獲得正確的帖子順序,有人對我可能做錯了什么有任何建議嗎?再次感謝所有的幫助和提示。
使用 Sequalize 按連接表計數列排序
叮當貓咪
2023-05-25 16:04:57