Odoo Help

Welcome!

This community 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.

0

How to find out the table name for a many2many relation (Where is the many2many table name stored?)

By
Tanveer Singh
on 5/21/15, 2:36 AM 1,266 views

Hi,

I am trying to recover data from a broken odoo installation (uprade got screwed up).

I have exported all the tables to CSV using postgresql (psql). I would also be able to handle many2one and one2many relations.

For many2many relations, I need a way to programatically find out which database table contains the relation details (ids from both the models). I tried to get the data from the ORM "fields_get" function using xmlrpc. The  field definition returns a dictionary which has a key named 'relation'. However this key contains just the name of the other table/ model involved in the relation. For many2many relations there is another 3rd table involved. I am unable to find where odoo stores the name of this table.

Regards,

Tanveer

You can get the name of the relation table by seeing the fields definition only. Or, odoo maintains a separate table called 'ir_model_relation' containing the module id(like, Project) and the object(model) id(like project_project ) with relation tables name for that object, you can use this table to get all the relation for that particular model(object) .

Pawan
on 5/21/15, 9:54 AM
0
Matt
On 11/24/15, 9:46 AM

In Odoo 9, you can query ir_model_fields to get the table name from the relation_table column.  
I'm not too sure about 7 and 8, but I think in 6.1 you could check the field definition from a fields get - something like:

self.fields_get(cr, uid, ['my_m2m_field'])['my_m2m_field']['third_table']

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 5/22/15, 1:39 AM

Hi,

You can get the name of the relation table by seeing the fields definition only. Or, odoo maintains a separate table called 'ir_model_relation' containing the module id(like, Project) and the object(model) id(like project_project ) with relation tables name for that object, you can use this table to get all the relation for that particular model(object) .

Thanks

Thanks Pawan. Your answer points me to the correct direction. I saw the ir_model_relation table, it provides the names of the many2many tables created by Odoo. However it only provides the module and model id references. When one model has more than one many2many fields, how to identity which row in the table 'ir_model_relation' refers to which field of the model?

Tanveer Singh
on 5/23/15, 6:41 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/21/15, 2:36 AM
Seen: 1266 times
Last updated: 11/24/15, 9:47 AM