我试着做一些我以为会很简单的事情,但似乎并不简单。
我有一个项目模型,有很多空缺。
class Project < ActiveRecord::Base
has_many :vacancies, :dependent => :destroy
end
I want to get all the projects that have at least 1 vacancy. I tried something like this:
Project.joins(:vacancies).where('count(vacancies) > 0')
但上面说
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) > 0)
.