Skip to content

Commit d94144b

Browse files
KangOlPirols
authored andcommitted
[IMP] convert_m2o_field_to_m2m
Use the new API of `create_m2m` and let it compute the m2m table name. closes #304 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 4a9fdd8 commit d94144b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/util/fields.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def make_index_name(table_name, column_name):
4444
from .exceptions import SleepyDeveloperError
4545
from .helpers import _dashboard_actions, _validate_model, resolve_model_fields_path, table_of_model
4646
from .inherit import for_each_inherit
47-
from .misc import log_progress, safe_eval, version_gte
47+
from .misc import AUTO, log_progress, safe_eval, version_gte
4848
from .orm import env, invalidate
4949
from .pg import (
5050
SQLStr,
@@ -756,15 +756,12 @@ def convert_m2o_field_to_m2m(cr, model, field, new_name=None, m2m_table=None, co
756756
table1 = table_of_model(cr, model)
757757
table2, _, _ = target_of(cr, table1, field)
758758

759-
if m2m_table is None:
760-
m2m_table = "{}_{}_rel".format(*sorted([table1, table2]))
761-
762759
if col1 is None:
763760
col1 = "{}_id".format(table1)
764761
if col2 is None:
765762
col2 = "{}_id".format(table2)
766763

767-
create_m2m(cr, m2m_table, table1, table2, col1, col2)
764+
m2m_table = create_m2m(cr, m2m_table or AUTO, table1, table2, col1, col2)
768765

769766
dedup = SQLStr("ON CONFLICT DO NOTHING")
770767
if cr._cnx.server_version < 90500:

0 commit comments

Comments
 (0)