2016-10-18 76 views
3

事件包含一列popularity和許多關鍵字。關鍵字有一個類別和一個名稱。我試圖按照他們的流行度來排列事件,但是隻能將每個關鍵字名稱中最受歡迎的事件與「分類法」類別歸類在一起。PG :: GroupingError:錯誤:列「events.id」必須出現在GROUP BY子句中或用於聚合函數中

這裏是我的查詢:

Event.order(:popularity).joins(:keywords).where(keywords: {category: "taxonomy"}).group("keywords.name") 

但我得到以下錯誤:

PG::GroupingError: ERROR: column "events.id" must appear in the GROUP BY clause or be used in an aggregate function

我要去哪裏錯了?

+0

Postgres版本?有些人建議使用9.1 – Sajan

回答

5
Event.order(:popularity) 
    .joins(:keywords) 
    .group('events.id') # <====== 
    .where(keywords: { category: 'taxonomy' }) 
    .group('keywords.name') 
+1

非常感謝,非常感謝 –

相關問題