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?
Table res_partner
has many2many field category_id
relating to table res_partner_category.res_partner
, or let's just say partners can have many categories. What I need is to filter res_partners
table where it has category named 'business' or 'retail'. If it doesn't have any of these categories, it should not be shown.
Also there is another field in res_partner
which is category_value_ids
and has one2many
relation with res_partners_category_value
:
res_partner
has following fields with relations:
category_id
tores_partner_category
(many2many)category_value_ids
tores_partner_category_value
(one2many)name
(char)
res_partner_category
has following fields with relations:
partner_ids
tores_partner
(many2many)name
(char)
res_partner_category_value
has following fields with relations:
category_group_id
tores_partner_category
(many2one)category_id
tores_partner_category
(many2one)object_id
tores_partner
(many2one)
But if I try to use res_partner_category_value
table in SQL query I get error that I can't use it in query.
So for example, if there are 4 partners with these categories:
- first: categ1, categ2, business
- second: retail
- third: retail, business
- fourth: categ1, categ2
The query should return first, second and third partners.
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?
EDIT:
I found one more table called res_partner_category_rel
. 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:
res_partner_category_rel:
partner_id
(many2one)category_id
(many2one)
res_partner
contains acategory_id
field... Why? – j_random_hacker