ORM Methods: Read()

amr gaberamr gaber
1 min read

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

0
Subscribe to my newsletter

Read articles from amr gaber directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

amr gaber
amr gaber

Hey! I'm Amr, a software engineer who is passionate about all things open source. I enjoy coding using Python.