0
私のアプリケーションで私はモデルがありますVisit
& Post
。Ruby on Rails - 結合とグループを実行するときのPostgreSQLグループ化エラー
class Post < ActiveRecord::Base
has_many :visits
class Visit < ActiveRecord::Base
belongs_to :post, :counter_cache => true
イムpost
がvisits
テーブルに持っているすべてのvisits
を取得しようとしています。これは、私の開発のenv/localhostの(私はsqlite3
を使用するので、私は思う)、ブーティで見つける働く
- 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
私の生産に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...
私は間違って何をやっているのですか?