Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As in Firebug's answer, you can think of the browse as a read or in simple terms, a SQL select statement but with a few differences. Technically, they represent an instance of the data defined by an ORM model - product.product defines the model (or table), a browse record is a row of data from the table.</p> <p>Browse takes either a single ID (e.g. 1) and returns a browse record or takes a list of Ids <code>[1,2,3...]</code> and returns a list of browse records.</p> <p>It does ultimately read from the database but it also does a few other things that a read doesn't;</p> <ol> <li>Caching</li> <li>Lazy loading to any depth (<code>sale_order_line.sale_order.partner.email</code>)</li> <li>Handles virtual fields such as functional fields, relational fields (many2one,one2many), related fields.</li> </ol> <p>In the simplest sense, think of it as <code>select * from my_table where id = %s</code> and then assembling an object from the result.</p> <p>A few things to note:</p> <ol> <li>Browse records always have an ID - e.g. <code>product.id</code></li> <li>You can't pass browse records to a client. They lazily load and hold on to a database cursor, if you try you see the "cursor used after being closed" message.</li> <li>They don't handle browsing missing records very well. Make sure the records you are browsing exist. Normally this isn't something you have to worry about, but if you need to be sure, do a search.</li> <li>Browse records implement <code>__eq__</code> so you can go <code>if product_browse_record == other_product_browse_record</code> and it works.</li> <li><p>A very common pattern is as you have above:</p> <p>for product in product_model.browse(cr, uid, ids, context = context): do something with my product</p></li> </ol> <p>This is fine 99 times out of 100 but be aware that it will read all the database records in one go and construct a list of the objects. If you have a huge list of IDs, you will use a big chunk of memory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload