Hi,
I have found in official addons that even though a record has a reference to other records (like one2many), and they already have a browse record with the required information, the programmer still uses the search function to get the list of ids from the database.
Example:
Each hr_employee
has a field contract_ids
, that is a one2many relationship to hr_contract
.
If I already have
employee_data = employee_obj.browse( blah, blah, blah...)
and I want to access the list of contracts for that employee, what is the right way to get it:
a) Use the list I already have on employee_data.contract_ids and get the information from there,
or
b) Execute a search on contract object looking for contracts related to the employee, like:
contract_ids = obj_contract.search(cr, uid, [('employee_id','=',emp.id),], context=context)
I would think option a), but I have found that in most cases option b) is used in official addons, so I guess there is a reason for that...
What are cons and pros of each aproach ?
The advantage of first method is that you have an access directly to browse_records. In the second way you must call a browse() method on obj_contracts with your contract_ids to access to their attributes. But I don't know about performances. You must know that many of addons was written in old versions of OpenERP. Maybe browse method was not so efficiently than know...?