title: Rails/Postgres: column must appear in the GROUP BY clause
body: <p>I have a scope that joins users to posts, to get only users that have visible posts.  This works in MySQL, but PG is a lot more strict, and throws an error.</p>
  
  <p>User Model:</p>
  
  <pre><code>belongs_to :account
  
  scope :have_posts, joins(:posts).where('posts.visible =&gt; true').group('users.id')
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@account.users.have_posts.each do |user|
    # do stuff
  end
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>(PGError: ERROR:  column "users.account_id" must appear in the GROUP BY clause or be used in an aggregate function: SELECT     "users".* FROM       "users"  INNER JOIN "posts" ON "posts"."user_id" = "users"."id" WHERE     ("users".account_id = 1) AND (recommendations.approved = true) GROUP BY  users.id)</p>
  </blockquote>
  
  <p>It's complaining about "users.account_id" which is from calling <code>@account.users</code> (as I obviously don't want all users in the DB).</p>
  
  <p>Any idea how to fix?</p>