December 2018
Beginner to intermediate
404 pages
10h 14m
English
A one-to-many relationship is the inverse of the many-to-one. It lists the records of the related Model that have a reference to this record.
For example, in the library book model, the publisher_id field is a many-to-one relationship with the partner model. This means that the partner model can have a one-to-many inverse relation with the book model, listing the books published by each partner.
To have that relationship available, we can add it in the partner model. Add the library_app/models/res_partner.py file with this:
from odoo import fields, modelsclass Partner(models.Model):
_inherit = 'res.partner'
published_book_ids = fields.One2many(
'library.book', # related model
'publisher_id', # field ...Read now
Unlock full access