Odoo Help


Many2Many relationship; how to make it two-way?

Mohamed Mahmoud
on 3/18/15, 12:19 AM 1,693 views

Hi all,

I have created a many2many relationship via Python code between partners to allow partner A to have more than one associated company B & C for example. 

Now, if I go to partner B or C, I am expecting to see A; but, this is not the case. 

I think this behavior is normal; because I only added the records for B & C under A and not the other way around.

Any idea how I can make this happen the other way around?

Thanks in advance.



Jordan Vrtanoski
On 3/18/15, 1:41 AM

In Odoo7 you can use the "fields.related" type of fields.

In Odoo8 the "fields.related" are replaced with attributes on the relations fields (one2many, many2one and many2many). The parameters are "related=". Following is example of the related field: 

fields.Char(related=’user_id.partner_id.name’, store=True)
Baiju KS
On 3/18/15, 1:33 AM

Hi ,,

Here is the syntax for many2many:-

field_name = fields.Many2many ( 'res.partner.category',  'res_partner_category_rel',  'partner_id',  'category_id',  'Categories'),

Example with book and author:-

In author-

book_ids = fields.Many2many('op.book', 'book_author_rel', 'op_author_id', 'op_book_id', string='Books'),

In book-

author_ids = fields.Many2many('op.author', 'book_author_rel', 'op_book_id', 'op_author_id', string='Author'),

And you can link between both books and authors and its bidirectional.

Hope this helps...

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/18/15, 12:19 AM
Seen: 1693 times
Last updated: 3/18/15, 1:41 AM