ORM Methods: Read()

Retrieving Data Efficiently: Using read() in Odoo

This method allows you to read data from the database.

It takes a list of fields as input and returns a list of dictionaries mapping field names to their values.

Parameters:

fields: This parameter specifies which fields you want to read from the database. If you do not specify any fields, the read function will return all fields for the record.

Example

fields = ['name', 'email']
res = self.env['res.partner'].browse( (7,8) ).read(fields)

Result

# [
{'email': 'mark.brown23@example', 'id': 7, 'name': 'Marc Demo'},
{'email': 'joel.willis63@example', 'id': 8, 'name': 'Joel Willis'}
]

How it works?

This method works by first fetching the stored fields (fields that are stored in the database) from the database to the cache.

Why is it important?

  • Send data to another system (Integration)

  • Display data in a list view or form view

  • Export data to a file

ย