ORM(Object Relational Mapping) is a concept or technique which acts as a bridge between your programming language and your database. 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. ORM methods are one of its strong features which helps in executing SQL queries without writing them down explicitly. With the help of ORM methods, the user can implement the OOPS concepts to interact with the database. Odoo creates and manages tables for us inside the database. Thus reducing our work of creation of tables using the queries.
2. INTRODUCTION
❖ 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.
❖ ORM methods are one of its strong features which helps in executing SQL queries
without writing them down explicitly. With the help of ORM methods, the user can
implement the OOPS concepts to interact with the database.
❖ Odoo creates and manages tables for us inside the database. Thus reducing our work of
creation of tables using the queries.
3. ❖ sorted ( )
○ The sorted() method returns the records inside the self, ordered by the key
passed as the argument.
○ Syntax: Model.sorted(key=None, reverse=False), If reverse is set as True, returns
the result in reverse order.
○ Eg: records.sorted(key=lambda r: r.name) - Sorts the record based on the name
field.
4. ❖ mapped ( )
○ The mapped() function applies the function given as an argument on all the
records in the self, and then returns the result as a list or recordset. This method
accepts a function as its argument.
○ Syntax: Model.mapped(func) ? recordset / list
○ Eg: records.mapped(lambda r: r.field1 + r.field2) - This returns a list of summing two
fields for each record in the set.
5. ❖ filtered ( )
○ The filtered method returns a set of records which satisfies the function given as
argument. This method accepts a function as its argument.
○ Syntax: Model.filtered(func) ? records
○ Eg: records.filtered(lambda r: r.company_id == user.company_id) - This only
keeps records whose company is the current user's.
6. For More
Details
Check our company website for related blogs and Odoo book.
Common ORM Methods
ORM (Object Relational Mapping) in Odoo
Check our YouTube channel for functional and technical
videos in Odoo.
Odoo ORM Methods