title: SQLAlchemy - Query parent by its childer, filter a join to match every children in a list
body: <p>I am trying to query a Person who has all of the requested Skills. Not sure what is the best way to build the query dynamically.</p>
  
  <p>ORM Objects are below. Many-to-many between Person and Skills, connecting table not included here:</p>
  
  <pre><code>Person
  name=John, skills=[Skill(id=1)] # John knows Python
  name=Eve, skills=[Skill(id=1), Skill(id=2)] # Eve knows Python and SQLAlchemy
  
  Skill
  id=1, name=Python
  id=2, name=SQLAlchemy
  id=3, name=Social skills
  </code></pre>
  
  <p>On a search page user selects one or many skills and a search result of Persons is created based on this. Let's say an user wants to find a person who knows Python and also SQLAlchemy. Application gets a list of two ids from the form submit, [1, 2]. I got the following query to kind of work, to find the persons with matching skills:</p>
  
  <pre><code>session.query(Person)./
  join(Skill, Person.skills).filter(Skill.id.in_(list_of_skill_ids))
  </code></pre>
  
  <p>However, using the in_ clause causes John person to be found as he has one of the required skills. But the search result should only show persons who have all of the requested skills. Basically what I want is something like in_() but which user <em>and</em> instead of <em>or</em> to match the id list. I probably should replace the in_() part with this, which does not take the id list directly:</p>
  
  <pre><code>filter(Person.id == 1, Person.id == 2)
  </code></pre>
  
  <p>But what is the easiest way to build the query programmatically using the the list of skill ids that I receive from the form? Number of ids can be 1..n. Or is this even the right way to query a parent by its children?</p>