ORM
ORM Methods in odoo :
- ORM is stands for Object Relational Mapping
- Used to convert data between incompatible type system
- Odoo modeling is based on "objects" but it's data is stored in a classical relational database
search()
Use
to search for records in object
Input
> search domain
Output
> list of ids
Employee_ids = self.env[‘hr.employee’].search([‘age’,’=‘,65])
browse()
Use
to get record set
Input
> list of ids
Output
> record set
faculty
= self.pool.get('op.faculty').browse(self.cr,
self.uid, faculty_id)
create()
Used
to create new records in object
Input
> field’s values
Output
> create new reord in
object
Employee_id = self.env[‘hr.employee’]
Employee_ids.create({‘name’:Juhn,’age’:28,’gender’:’male’})
write()
Used
to write our update values of records
Input
> field’s values
Output
> write these values to all records in it’s record set
Employee_id = self.env[‘hr.employee’].search([(‘id’,’=’,1)])
Employee_ids.write({‘name’:’mark’,’age’:38})
Write () with relational fields
0, 0,
{ values }) link to a new record that
needs to be created with the given values dictionary
(1,
ID, { values }) update the
linked record with id = ID (write values on it)
(2,
ID) remove and delete the
linked record with id = ID
(3,
ID) cut the link to the linked record with id = ID
(4,
ID) link to
existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6,
0, [IDs]) replace the
list of linked IDs
exists()
Returns
a new recordset
containing only the records which exist in the database
if
not record.exists():
raise Exception("The record has been deleted")