Querying data with recordsets and domains
Inside a method or a shell session, self
represents the current model, and we can only access that model's records. To access other models, we should use self.env
. For example, self.env['res.partner']
returns a reference to the Partner model (which is also an empty recordset).
We can then use search()
or browse()
on it to retrieve recordsets, and the search()
methods use a domain expression to define for the record selection criteria.
Creating recordsets
The search()
method takes a domain expression and returns a recordset with the records matching those conditions. An empty domain []
will return all records.
Note
If the model has the active
special field, by default only the records with active=True
will be considered.
The following keyword arguments can also be used:
order
is a string to be used as theORDER BY
clause in the database query. This is usually a comma-separated list of field names. Each field name may be followed by theDESC
keyword, to indicate...