Traversing recordset relations
When working with a recordset with a length of
1, various fields are available as record attributes. Relational attributes (
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 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.
We will reuse the
library.book model that was shown in the Creating new records recipe in this chapter.
How to do it...
To get the names of authors from the book recordset, you need to...