Adding relational fields to a model
Relations between Odoo models are represented by relational fields. There are three different types of relations:
- many-to-one, commonly abbreviated as m2o
- one-to-many, commonly abbreviated as o2m
- many-to-many, commonly abbreviated as m2m
Looking at the Library Books
example, we can see that each book can only have one publisher, so we can have a many-to-one relation between books and publishers.
Each publisher, however, can have many books. So, the previous many-to-one relation implies a one-to-many reverse relation.
Finally, there are cases in which we can have a many-to-many relation. In our example, each book can have several (many) authors. Also, inversely, each author may have written many books. Looking at it from either side, this is a many-to-many relation.
Getting ready
We will continue using the my_library
add-on module from the previous recipe.
How to do it...
Odoo uses the partner model, res.partner...