跳至内容
菜单
此问题已终结
4 回复
23607 查看

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) .

最佳答案

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?

最佳答案

i want to explain how odoo framework create related table for many2many for exemple we have your model1 where you created "category_id" and the other model2 where you Create the relation with many2many

Now for each models odoo create table in Psql , so for models1 odoo create in Psql table:model1and for the second model Psql create table: Model2 and for the relation many2many Psql create the third his name is table:model1_Model2

so in odoo create this table with underscore and the 2 table Name

形象
丢弃
最佳答案

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']

形象
丢弃
最佳答案

Go to settings and from technical menu there is many2many option from where you can fetch all the many2many tables of your project

形象
丢弃
相关帖文 回复 查看 活动
0
9月 17
6307
4
10月 17
27931
2
6月 16
10961
1
6月 15
17963
0
3月 15
4106