ORM methods in odoo

ORM Methods In Odoo:

ORM means “Object Relational Mapping” this are the method used in odoo14 to control the database, without using sql codes.

Types of orm method .

1.search()

2.browse()

3.create()

4.update()

SEARCH METHOD IN ODOO 14

SEARCH  function is an odoo ORM method that is responsible for searching the specific records by some field values in a relational field. This is used for example to provide suggestions based on a partial value for a relational field.

Syntax as follows:

 self.env[‘<model name>’].search([(‘<domain>’)])

In Practical Case:

self.env[‘res.partner’].search([(‘supplier’,’=’,True)])

 

This will return the record inside the ‘res.partner’ model with field ‘supplier’ as True.

 

BROWSE METHOD IN ODOO

The browse() method is used to return a set of records for the IDs passed as the parameter in the current working model. This method accepts a set of IDs and returns the record sets corresponding to that IDs.

Syntax as follows:

self.env[‘<model name>’].browse([(‘<domain>’)])

In Practical Case:

self.env[‘res.partner’].browse([(‘supplier’,’=’,True)])

Here instead of search we use browse in same model “res.partner” with same fiels “supplier” as True.

CREATE METHOD IN ODOO

Create method is used for creating new records inside the specified model. So for this we also have to specify the field name and the value to be inserted.

Syntax as follows:

self.env[‘<model name>’].create({

‘<field_name>’:'<value>’

})

In Practical Case:

self.env[‘res.partner’].create({

‘name’:’Manu’,

‘supplier’:True,

})

UPDATE METHOD IN ODOO

This method is used for updating values inside the model with some domain.

Syntax as follows:

<variable_name>.update({

‘<field_name>’:'<value>’

})

In Practical Case:

vals=self.env[‘res.partner’].search([(‘supplier’,’=’,True)]

vals.update({

‘supplier’:False,

})

 

To Know more About Us

 

 

 

Leave a Reply

Your email address will not be published.