OdooWiki OCA HUB

Base Many2many Custom Field

base_m2m_custom_field folder_open OCA/server-tools open_in_new
Technical Settings License: AGPL-3

This module adds a new Many2many custom field with a create_table attribute.

auto_awesome What this module does

AI-generated from the code · Odoo 18.0

Adds a new technical field type that lets developers control whether the database link table for a many-to-many relation is created automatically. It changes nothing visible for everyday users.

This is a technical module with no screens, menus or reports. It introduces a new field type, Many2manyCustom, which behaves like a normal many-to-many field but adds one option: create_table.

  • When create_table is left at its default value (true), the field works exactly like a standard many-to-many field and its relational database table is created when the field is set up.
  • When create_table is set to false, the module skips the automatic creation of that relational table.

This gives developers a way to declare a many-to-many relation whose link table is managed elsewhere, for example created by another module or by a manual database script, without Odoo trying to create it again.

The module depends only on base and does not add any model, view, menu, button, report, scheduled action or business rule. It does not change any existing Odoo screen or workflow. Its effect is limited to how the database structure is built when a field of this new type is used in custom development.

Depends on

base

Text generated by AI (DeepSeek) from reading the Odoo 18.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 6 confirmed, 3 with no information of 9 versions.

Sources · Odoo 18.0

Confirmed on 2026-11-03 in branch 18.0 of OCA/server-tools.

terminal Installation and usage

OCA documentation · Odoo 18.0

Many2manyCustom field is useful when a direct access to the relational table is needed, for example to be editable in a dedicated tree view.

Let's consider following models:

class MyModelA(models.Model):

    _name = 'my.model.a'

    my_model_b_ids = fields.Many2manyCustom(
        'my.model.b',
        'my_model_a_b_rel',
        'my_model_a_id',
        'my_model_b_id',
        create_table=False,
    )


class MyModelB(models.Model):

    _name = 'my.model.b'

    my_model_a_ids = fields.Many2manyCustom(
        'my.model.a',
        'my_model_a_b_rel',
        'my_model_b_id',
        'my_model_a_id',
        create_table=False,
    )


class MyModelABRel(models.Model):

    _name = 'my.model.a.b.rel'

    my_model_a_id = fields.Many2one(
        'my.model.a',
        required=True,
        index=True,  # Index is mandatory here
    )
    my_model_b_id = fields.Many2one(
        'my.model.b',
        required=True,
        index=True,  # Index is mandatory here
    )

By setting create_table=False on the Many2manyCustom field, and using the relational table name, as _name for the relational model, we're able to define a dedicated tree view for my.model.a.b.rel.

<record id="my_model_a_b_rel_list_view" model="ir.ui.view">
    <field name="name">my.model.a.b.rel.list.view</field>
    <field name="model">my.model.a.b.rel</field>
    <field name="arch" type="xml">
        <list editable="top">
            <field name="my_model_a_id" />
            <field name="my_model_b_id" />
        </list>
    </field>
</record>

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.