ORM(Object Relational Mapping) is a concept or technique which acts as a bridge between your programming language and your database. The Object Relational Mapping helps to execute SQL queries without writing them explicitly. Once the ORM is configured in an application, the user can use the OOP concepts like classes and objects to interact with the database.
2. ORM(Object Relational Mapping) is a concept or technique which
acts as a bridge between your programming language and your
database. The Object Relational Mapping helps to execute SQL
queries without writing them explicitly. Once the ORM is
configured in an application, the user can use the OOP concepts
like classes and objects to interact with the database.
3. Major functions of ORM are
● Create :
Model.create(vals_list)
Create() method is used to create new records in a model.vals_list is the dictionary used to
initialize new records using the value.
● Write :
Model.write(vals)
Which is used to update all records in the current set with the specified values.
● Search/Read :
Model.search(args[, offset=0][, limit=None][, order=None][, count=False])
Which searches for the records in the args domain.
4. Model.search_count(args)
Which returns the number of records in the current model that matches the specified domain.
Model.name_search(name='', args=None, operator='ilike', limit=100)
It finds records with a display name that matches the specified name pattern when compared
to the specified operator and also matches the optional search domain (argument).
This method is the same as calling search () on the search domain based on display_name and
then name_get () based on the search results.
Model.read([fields])
Read the requested field of the record, And it is a low level / RPC method. In Python code, use
browse ().
● Browse
Model.browse([ids])
Returns a record set of IDs provided as parameters in the current environment.
5. Model.read_group(domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True)
Gets a list of records in the listview grouped by the specified group by field.
● Fields/Views
Model.fields_get([fields][, attributes])
Returns the definition of each field.
The return value is the dictionary (indexed by field name). Contains the _inherits'd fields.
Strings, help, and selections (if any) attributes are converted.
Model.fields_view_get([view_id | view_type='form'])
Gets the detailed configuration of the requested view, including fields, models, and view
architecture.
6. ● Unlink
Model.unlink()
Delete the records in the current record set.
Model.exists()
The present () method returns a subset of the records that exist within itself. Returns a
recordset containing only the records that exist in the database. It can also be used to check if
a particular record still exists.
Model.ensure_one()
The ensure_one() method checks if the record set contains only one record. If not, throw an
exception.
7. ● Filter
Model.filtered(func)
Which returns the record which satisfies func.
• Map
Model.mapped(func)
Apply func to all of its own records and return the result as a list or record (if func returns a
record). In the latter case, the order of the returned records is arbitrary.
• Sort
Model.sorted(key=None, reverse=False)
Returns a self-ordered Recordset with the key.
8. With ORM, you don't have to worry about creating databases or mapping fields between
front-end databases. The table and its fields are automatically created based on the class you
created in Odoo. You may also need to perform some calculations and perform some
operations before adding them to the database. This can be overridden via the Odoo Orm
method to perform such operations.
9. Check our company website
for related blogs and Odoo book.
https://www.youtube.com/watch?v=A8MEl4BfqyY