Traversing recordset relations
When working with a recordset with 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 hostel.room
model. You can access the category name by traversing through the Many2one
field’s category_id
as follows: room.category_id.name
. However, when working with recordsets with more than one record, the attributes cannot be used.
This tutorial demonstrates how to navigate recordset relations using the mapped()
function. We’ll create a function to extract the members’ names from the list of rooms that are supplied as input.
Getting ready
We will reuse the hostel.room
model that was shown in the Creating new records tutorial in this chapter.
How to do it…
You must do the following actions in...