I have three models
class Person < ActiveRecord::Base
has_many :assignments
has_many :projects, through: :assignments
end
class Project < ActiveRecord::Base
has_many :assignments
has_many :people, through: :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :person
belongs_to :project
end
I'm using a attribute called 'kind' on the Assignment model to determine how the person is associated with the property. It's a string field and possible values include: 'supervisor', 'worker', 'inspector'.
I've added the attribute to the Assignment model rather than the Person model because in some scenarios its possible for a person to be a worker on one project, and a supervisor on another at the same time.
Its important to note, that when created a supervisor is automatically assigned. Therefore all projects will have at least one assignment already.
What I'm wondering is this:
How do I query all projects which have no workers assigned? This would be a project which has no assignments which have 'worker' in the kind column.