Why is your code not working?
Project.where(:is_available?)
, where, (SQL). , , is_available? true. , is_available? - Ruby ( ). Ruby, SQL. where SQL, ruby.
( @benzado )
:
, , db:
Project.joins(:workers)
.select('projects.*')
.group('projects.id')
.having('COUNT(workers.*) > 2')
, 2 , .
?
, :
class Project < ActiveRecord::Base
scope :having_more_than_x_workers, lambda do |workers_count|
joins(:workers).select('projects.*').group('projects.id').having("COUNT(workers.*) > #{workers_count || 0}")
end
end
, , :
def index
@projects = Project.having_more_than_x_workers(2)
end