0
在我的應用程序中,我有模型Visit
& Post
。Ruby on Rails - PostgreSQL在加入羣組時出現分組錯誤
class Post < ActiveRecord::Base
has_many :visits
class Visit < ActiveRecord::Base
belongs_to :post, :counter_cache => true
我試着讓所有visits
一個post
在visits
表。我所做的:
- a = Visit.joins(:post).group(:post_id).select(:post_id, :title, 'count(visits.id) as total_views').where(user: current_user)
- a.each do |a|
%tr
%td= a.title
%td= a.total_views
這工作找到自己的發展ENV /本地主機(我想既然我用sqlite3
),布提現在用PostgreSQL的在我生產,我得到這個錯誤:
PG::GroupingError: ERROR: column "posts.title" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...ECT count(visits.id) as total_views, "visits"."post_id", "title", c...
我在做什麼錯,怎麼解決?