Many2one, One2many, and Many2many Fields in Odoo

The relational field types connect records. The three kinds, and what each is for.

The connectedness of records is central to Odoo, and the relational field types are how records are connected. This piece is about the three of them: Many2one, One2many, and Many2many.

Why relational fields matter

Records in Odoo are connected, an order to a customer, a record to other records, and that connectedness is fundamental to how Odoo works. The relational field types are the field types that create those connections: a relational field on a record holds a connection to other records. There are three relational field types, and they correspond to the three genuine kinds of relationship a record can have.

Many2one: this record points to one other

A Many2one field holds a connection from this record to one other record. The name describes the relationship: many records of this kind can each point to one record of the other kind. An order pointing to its customer is a Many2one: each order points to one customer, and many orders can point to the same customer. The Many2one is the field type for "this record is connected to one particular other record". It is the most fundamental relational field, the simple connection from a record to a single other.

One2many: the other side, one record has many

A One2many is, in a sense, the other side of a Many2one. Where a Many2one is many records each pointing to one, the One2many is the view from that one: the one record having many records that point to it. The customer, seen from the Many2one of the orders pointing to it, has a One2many of those orders: the one customer has many orders. A One2many field, on a record, gives access to the many records that point to it. The One2many and the Many2one are the two sides of the same relationship, seen from each end.

Many2many: records connected on both sides to many

A Many2many is a different kind of relationship: where records on each side can be connected to many on the other. Not many-to-one, but many-to-many. The classic case is something like tags: a record can have many tags, and a tag can be on many records. Neither side is "the one"; both sides connect to many. A Many2many field holds that kind of connection, where this record connects to many others and they connect to many records like this one.

Choosing the right relational field

The practical point for a developer is to choose, for each connection a record genuinely has, the relational field type that genuinely matches the kind of relationship. If this record is genuinely connected to one particular other, a Many2one. If this record is the one that many others point to, a One2many giving access to them. If records on both sides genuinely connect to many, a Many2many. Choosing the relational field type that matches the genuine relationship is part of defining a model that genuinely reflects how its records connect to others. A wrong relational field type models the connection wrongly.

The takeaway

Many2one, One2many, and Many2many are the relational field types in Odoo, the field types that connect records, and they correspond to the three kinds of relationship. A Many2one connects this record to one particular other. A One2many is the other side, the one record's access to the many that point to it. A Many2many connects records that, on both sides, relate to many. A developer should choose, for each genuine connection, the relational field type that matches the kind of relationship. For how we approach Odoo, see our ERP practice.

All posts

Got a Topic Worth Posting?

Suggest a Topic

If a question keeps coming up in your operations, it might be worth its own post.