title: Find all records which have a count of an association greater than zero
body: <p>I'm trying to do something that I thought it would be simple but it seems not to be.</p>
  
  <p>I have a project model that has many vacancies.</p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
  
    has_many :vacancies, :dependent =&gt; :destroy
  
  end
  </code></pre>
  
  <p>I want to get all the projects that have at least 1 vacancy.
  I tried something like this:</p>
  
  <pre><code>Project.joins(:vacancies).where('count(vacancies) &gt; 0')
  </code></pre>
  
  <p>but it says</p>
  
  <p><code>SQLite3::SQLException: no such column: vacancies: SELECT  "projects".* FROM "projects" INNER JOIN "vacancies" ON "vacancies"."project_id" = "projects"."id" WHERE ("projects"."deleted_at" IS NULL) AND (count(vacancies) &gt; 0)</code>.</p>