Find all records which have a count of an association greater than zero

后端 未结 10 1649
北海茫月
北海茫月 2020-11-30 17:45

I\'m trying to do something that I thought it would be simple but it seems not to be.

I have a project model that has many vacancies.

class Project &         


        
10条回答
  •  心在旅途
    2020-11-30 18:00

    The error is telling you that vacancies is not a column in projects, basically.

    This should work

    Project.joins(:vacancies).where('COUNT(vacancies.project_id) > 0')
    

提交回复
热议问题