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...
我在做什么错,怎么解决?