SQL Execution
The cr property on environments represents the cursor for the current database transaction.
It enables you to execute SQL directly instead of through the ORM, which is beneficial for queries that are difficult to construct using the ORM. (e.g., complex joins) or for performance reasons:
self.env.cr.execute("some_sql", params)
While all models use the same cursor and the environment has a variety of caches, updating the database in raw SQL necessitates destroying these caches, or else the model use would become nonsensical. When using CREATE, UPDATE, or DELETE in SQL, clearing caches is necessary, but not when using SELECT (which merely reads the database).
The invalidate cache() method can be used to clean caches.
invalidate_cache(fnames=None, ids=None)
Invalidate the record caches when some records have been changed. The whole cache is cleaned out if both fnames and ids are None.
Parameters:
fnames – The changed fields list, or None for every field.
ids – The changed record id list, or None for every record.