My models
class Person
embeds_many :skills, class_name: "PersonSkill"
class Project
embeds_many :skills, class_name: "ProjectSkill"
class Skill
belongs_to :tag # Tag class is irrelevant for my question I think
field :tag_name # Assume it's synchronised with tag.name
class PersonSkill < Skill
embedded_in :person
class ProjectSkill < Project
embedded_in :project
Now I need to build a few queries/scope. The idea is that projects have many skills, and the Project managers want to be able to find a list of people who do have those skills
Basically : several skills [skillA, skillB, skillC] are associated to project A. A project manager wants to find people with
- skillA AND skillB
- skillA OR skillB
- (skillA AND skillB) or (skillA AND skillC)
Is it possible to define some nice mongoid scopes that would let me do that easily?
I had a look at this question and I came up with the following scope, but it only covers one of the 3 cases mentionned above.
scope :with_skills, ->(tag_ids){where('competences.tag_id' => {'$in' => tag_ids})}