Singletons

The special case of a recordset with only one record is called a singleton. Singletons are still a recordset, and can be used wherever a recordset is expected. 

But unlike multi-element recordsets, singletons can access their fields using the dot notation, like this:

>>> print self.name 
Administrator 

In the next example, we can see the same self singleton recordset also behaves as a recordset, and we can iterate it. It has only one record, so only one name is printed out:

>>> for rec in self: 
      print rec.name 
Administrator 

Trying to access field values on recordsets with more than one record will result in an error, so this can be an issue in the cases where we are not sure if we are working with a singleton recordset. For methods ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.