title: Many-to-many relation filter
body: <p>I need to filter my query with categories table which has many2many relation with another table. Is it possible to filter query with many2many relation? </p>
  
  <p>Table <code>res_partner</code> has many2many field <code>category_id</code> relating to table <code>res_partner_category.res_partner</code>, or let's just say partners can have many categories. What I need is to filter <code>res_partners</code> table where it has category named 'business' or 'retail'. If it doesn't have any of these categories, it should not be shown.</p>
  
  <p>Also there is another field in <code>res_partner</code> which is <code>category_value_ids</code> and has <code>one2many</code> relation with <code>res_partners_category_value</code>:</p>
  
  <p><strong><code>res_partner</code></strong> has following fields with relations:</p>
  
  <ul>
  <li><code>category_id</code> to <code>res_partner_category</code> (many2many)</li>
  <li><code>category_value_ids</code> to <code>res_partner_category_value</code> (one2many)</li>
  <li><code>name</code> (char)</li>
  </ul>
  
  <p><strong><code>res_partner_category</code></strong> has following fields with relations:</p>
  
  <ul>
  <li><code>partner_ids</code> to <code>res_partner</code> (many2many)</li>
  <li><code>name</code> (char)</li>
  </ul>
  
  <p><strong><code>res_partner_category_value</code></strong> has following fields with relations:</p>
  
  <ul>
  <li><code>category_group_id</code> to <code>res_partner_category</code> (many2one)</li>
  <li><code>category_id</code> to <code>res_partner_category</code> (many2one)</li>
  <li><code>object_id</code> to<code>res_partner</code> (many2one)</li>
  </ul>
  
  <p>But if I try to use <code>res_partner_category_value</code> table in SQL query I get error that I can't use it in query.</p>
  
  <p>So for example, if there are 4 partners with these categories:</p>
  
  <ul>
  <li>first: categ1, categ2, business</li>
  <li>second: retail</li>
  <li>third: retail, business</li>
  <li>fourth: categ1, categ2</li>
  </ul>
  
  <p>The query should return first, second and third partners.<br>
  One person told me it's not possible to filter like this with many2many relation. So I wonder is it really not possible or just complicated?</p>
  
  <p>EDIT:<br>
  I found one more table called <code>res_partner_category_rel</code>. I didn't see it, because in Openerp administration interface, where you can see all objects of database, that table is not shown. You can only see it directly through database.
  So I was confused by this "missing" table:</p>
  
  <p><strong>res_partner_category_rel:</strong></p>
  
  <ul>
  <li><code>partner_id</code> (many2one)</li>
  <li><code>category_id</code> (many2one)</li>
  </ul>