title: Filtering objects with many to many relationships
body: <p>I have a two tables one for documents one for mapping to categories.</p>
  
  <pre><code>Documents  
  id | document_name  
  1  | somename.doc  
  2  | anothername.doc  
  
  Documents_to_categories  
  cat_id | doc_id  
  10     | 1       
  10     | 2  
  11     | 3  
  12     | 1
  </code></pre>
  
  <p>Some documents can map to multiple categories. What I want is to be able to select documents that belong in multiple categories, like in a filtering scheme.</p>
  
  <p>Basically in the script I have an array of document id's that were a result from a search. I need to filter those documents down based on categories.</p>
  
  <p>This is what something like what I'm aiming for (I know it doesn't work but for example).</p>
  
  <pre><code>SELECT * 
   FROM Documents_to_categories A 
   JOIN Documents B ON A.doc_id = B.id 
  WHERE B.id IN (6703,6614,2286) 
    AND A.cat_id = :ID0 
    AND A.cat_id = :ID1
  </code></pre>
  
  <p>Edit: Sorry for all those who answered, my first time posting, was unclear with question. Hopefully this is more clear on what I want.</p>