Traversing recordset relations

When working with a recordset of a length of 1, various fields are available as record attributes. Relational attributes (One2many, Many2one, and Many2many) are also available with values that are recordsets too. As an example, let's say we want to access the name of the category from the recordset of the library.book model. You can access the category name by traversing through the category_id many2one field, as follows: book.category_id.name. However, when working with recordsets with more than one record, the attributes cannot be used.

This recipe shows you how to use the mapped() method to traverse recordset relations; we will write a method to retrieve the names of authors from the recordset of books, passed as an argument.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset