Relational Fields in Odoo15

In Odoo, we can link a record with another using the relational fields. This field makes the integration of modules happen as it connects each other by a field. In the case of creating a sale order, we need customer details, products, etc where these details come from different models.

So here we are going to see how the relational fields are used and how they impact our model. Basically, three types of relational fields are present and are as follows:

  1. Many2One
  2. One2many
  3. Many2many

Many2One Relational field:

In Odoo, we can connect an object of a model with another object of a comodel. Many2one relational field is used to provide a link to a comodel in Odoo. We can access the records, by calling the many2one field.

Relational Fields in Odoo15

Consider a student record under a student model. Here we need to get the tutor name which is under a tutor model. So we are defining a many2one field in our student model as,

After defining the field in model and view, we can see that,

Here we can see that the field Class Tutor, and is shown with a list of tutor names to select.

One2many Relational Field:

A one2many relation is generally an inverse of many2one relation as this connects a record to many other records in Odoo. This field cannot be viewed in the database under the model name, as it is created under another model database.

In simple words, when a user wants to store multiple entries in a record and wants to link this record and current record together, one2many relational field is used.

Relational Fields in Odoo15

For example, we have defined a one2many field inside the record course orders-

Relational Fields in Odoo15

Here the course.selection is the comodel and the many2one field in the comodel is the course_session_id .

Relational Fields in Odoo15

This is the one2many field shown as a table where multiple entries can be made. The field is defined in another model and its values are given from another model.

Many2many Relational field:

This relational field is used to create multiple relations between two models. This can be used to access as many records from another model. It also has a bidirectional nature as both models can access it.

Relational Fields in Odoo15

We are defining a many2one relational field for student onboarding records. Here tutor records are accessed with this relation.

Relational Fields in Odoo15
Relational Fields in Odoo15

And will be reflected in the record as,

Relational Fields in Odoo15

We can see the field Evaluation team, and we can choose as much as we need.

These are the three types of relational fields in Odoo. These fields are important in fulfilling the business requirement, as we have to link various kinds of information from different areas and then process it. We don’t have to revisit the different models to access the records.