In meiner Anwendung habe ich Modelle Visit
& Post
.Ruby on Rails - PostgreSQL Gruppierungsfehler beim Erstellen von Joins & Gruppe
class Post < ActiveRecord::Base
has_many :visits
class Visit < ActiveRecord::Base
belongs_to :post, :counter_cache => true
Im Versuch, alle visits
ein post
hat in visits
Tisch zu bekommen. Ich tat:
- 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
Dies funktioniert in meiner Entwicklung env finden/localhost (ich glaube, da ich sqlite3
verwenden), buti PostgreSql in meiner Produktion verwendet, und ich habe diesen Fehler:
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...
Was mache ich falsch und wie repariere ich es?