Rails4 订购方法在 PostgreSQL 中不起作用

Rails4 order method does not work in PostgreSQL

我创建了如下方法

def sort_by_footprints
  joins(:footprints).group(:article_id).order('SUM(articles.id) DESC')
end

但是当我使用 postgresql 时这不起作用,它说 ActionView::Template::Error (PG::GroupingError: ERROR: column "articles.id" must appear in the GROUP BY clause or be used in an aggregate function 我该如何解决?

试试这个:

joins(:footprints).group(:article_id).select('SUM(articles.id) as total_articles').order('total_articles DESC')