From 6af3193d17021108f7501cfda824e7a1aecc8a85 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 8 Jul 2014 13:55:48 +0200 Subject: [PATCH] [FIX] ir.model.fields: better unlink When droping a column, remove also the relation table in case of custom m2m field. The relation table needs to be dropped otherwise an unremovable constraint to the targetted table is kept (and anyway is not needed anymore). --- openerp/addons/base/ir/ir_model.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index e7775b8ecbc..966f5e29077 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -312,6 +312,14 @@ class ir_model_fields(osv.osv): if column_name and (result and result[0] == 'r'): cr.execute('ALTER table "%s" DROP column "%s" cascade' % (model._table, field.name)) model._columns.pop(field.name, None) + + # remove m2m relation table for custom fields + # we consider the m2m relation is only one way as it's not possible + # to specify the relation table in the interface for custom fields + # TODO master: maybe use ir.model.relations for custom fields + if field.state == 'manual' and field.ttype == 'many2many': + rel_name = self.pool[field.model]._all_columns[field.name].column._rel + cr.execute('DROP table "%s"' % (rel_name)) return True def unlink(self, cr, user, ids, context=None):