What is Object Relational Mapping in ROR?

ORM - Object Relational Mapping is a framework written in OOP Languages such as Java, Python, and Ruby. This framework wraps around a relational database such as MySQL.

ORM is a programming technique for converting data between incompatible systems in OOP languages. It also ensures that you do not have to call a database yourself.

ORM Framework and Ruby

Advantages

This concept of ORM is effective when dealing with databases.

Note: Not all ORM implementations support each of the following advantages.

In Ruby on Rails, ORM is:

  • Database Independent - There is no need to write code in a particular database. Simply start a project using MySQL and change it to SQLite later on.
  • Reduces Code - ORM provides the concept of abstraction, which means there’s no need to repeat the same code again and again.
  • Rich Query Interface - ORM allows the developer to get rid of the complex semantics of SQL.

ActiveRecords is a powerful framework of ORM in Ruby on Rails. Using the functionality provided by this module, you can:

  • Establish a connection to a database
  • Create database tables
  • Specify associations between tables that correspond to associations between the Ruby classes
  • Establish an ORM between Ruby classes/objects/attributes and the tables/rows/columns in the underlying database
  • Perform CRUD operations on Ruby ActiveRecord objects

Disadvantages

The ORM model is helpful in Ruby code completion and in implementing frameworks to reduce workload. However, it is still lacking in some areas, such as:

  • Overhead Issues - ORM consumes more memory than other relational databases and increases CPU usage.

  • Performance Issues - Some actions, such as inserting a large data, updating it, deleting it, etc., are slower when implemented using ORM. Native SQL queries can usually handle these actions more efficiently.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved