[FIX] orm: custom m2m with different label
authorMartin Trigaux <mat@openerp.com>
Fri, 11 Jul 2014 09:39:32 +0000 (11:39 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 11 Jul 2014 09:39:32 +0000 (11:39 +0200)
At rev 84e9a67cdf78db94cb7a09543c1b7ac4ad19d8b4 a check to avoid the creation of ir.model.relation for custom modules was added. The condition is not correct as based on the string instead of the field name. We do not have access to column name at this level but the the m2m relation table do start with x_ for custom fields (see __init__ method).

openerp/osv/orm.py

index 1f2823b..0a38ccf 100644 (file)
@@ -3387,7 +3387,8 @@ class BaseModel(object):
         m2m_tbl, col1, col2 = f._sql_names(self)
         # do not create relations for custom fields as they do not belong to a module
         # they will be automatically removed when dropping the corresponding ir.model.field
-        if not f.string.startswith('x_'):
+        # table name for custom relation all starts with x_, see __init__
+        if not m2m_tbl.startswith('x_'):
             self._save_relation_table(cr, m2m_tbl)
         cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (m2m_tbl,))
         if not cr.dictfetchall():