Vezi pagina în română

IT Glossary

What ORM (object-relational mapping) means and how it works

The software layer that translates between objects in code and the tables of a relational database, and writes the routine SQL in place of the developer.

7
sections
5
questions answered

ORM (object-relational mapping) is the software layer that automatically translates between the objects in an application’s code — a customer, an order, an invoice — and the tables of a relational database, generating the SQL for reading, saving and updating in place of the developer. In marketing the same abbreviation means online reputation management, so a search for “what is ORM” mixes two meanings; this page is about the programming one. Its best-known trap even has a name, the N+1 problem: the Laravel documentation shows that a list of 25 books displayed with each book’s author runs 26 queries, and only two with eager loading.

Application code thinks in objects, a database thinks in tables, rows and columns, and the ORM is the interpreter between them: a developer writes “save the order” and the ORM composes the SQL. Examples are Eloquent in Laravel, Doctrine in Symfony, Django ORM and SQLAlchemy in Python, Entity Framework Core in .NET, Hibernate in Java and Prisma in Node.js and TypeScript. For a company, a project built on a mature ORM is delivered faster and handed to another team more easily, but the team still has to know what SQL comes out of the code.

Why it matters for your business

Faster development

Routine database operations — saves, lookups, updates — take one line instead of a block of SQL; less code to write and review shows up directly in the project quote.

Parameterized queries by default

The ORM’s query builder binds parameters instead of gluing strings together, which closes the classic SQL injection route; the protection holds only as long as nobody concatenates text into raw SQL methods.

Changing the database is easier

The code talks to the ORM rather than directly to MySQL or PostgreSQL, so moving between engines takes far less effort, as long as the code avoids raw SQL and functions specific to one engine.

Other meanings: ORM in marketing

ORM also stands for online reputation management: monitoring reviews and mentions of a company, replying to them, and publishing content that improves how it appears in search. Marketing agencies sell it as a service and it has nothing to do with databases. If that is what you are after, this page is not the answer.

How an ORM works

An ORM keeps a simple correspondence: a table becomes a class (a model or entity), a row becomes an object, a column becomes a property, and a foreign key becomes a relation between objects. An invoice with its lines becomes an Invoice class with a “lines” relation, and the ORM composes the INSERT statements for the invoice and each line in a single transaction.

There are two classic designs, named by Martin Fowler in Patterns of Enterprise Application Architecture (2002). Active Record is an object that wraps a row in a database table and adds domain logic; Laravel’s Eloquent works this way. Data Mapper is a layer of mappers that moves data between objects and the database while keeping them independent; Doctrine and Hibernate work this way. Migrations complete the picture: versioned changes to the database structure.

Want an estimate for your project?

Message us on WhatsApp. We reply the same working day, and the first 30-minute call is free.

Book a free call

The N+1 problem and how to avoid it

The N+1 problem appears when code loads a list and then, in a loop, asks for each item’s relation, known as lazy loading. The Laravel documentation gives the example: 25 books displayed with their authors means 26 queries, and with eager loading, using the with method, only two. In Django the same fix is select_related, which fetches a foreign-key or one-to-one relation through a JOIN in a single query, and prefetch_related, which runs a separate lookup for each relation and joins them in Python. In Laravel, preventLazyLoading makes lazy loading throw an error outside production, so the trap is caught during development.

For a company the translation is concrete: a list of 100 invoices with their customers means 101 queries instead of two. It is invisible on ten test records and slow on real data. That is why it belongs on the code-review checklist.

ORM or hand-written SQL

The practical rule: an ORM for routine operations and business rules, hand-written SQL for reports, aggregations and bulk imports. Django’s optimization guide even has a “Use raw SQL” section for the cases an ORM cannot cover. Portability between engines ends exactly where raw SQL begins.

This is also the limit of SQL injection protection. The Laravel documentation says its query builder uses PDO parameter binding, but that it cannot guarantee protection for queries using raw expressions. Entity Framework Core parametrizes FromSql and FromSqlInterpolated, while FromSqlRaw with concatenated strings stays vulnerable. OWASP notes that ORM query languages, JPQL and HQL, can be injected too. Checked on 18 November 2026 against the Laravel, Django, EF Core and OWASP documentation.

For a company: what to ask the supplier

A mature, standard ORM in the framework makes handover to another team easier, but quality depends on who uses it. Four questions help when comparing offers: which ORM do you use, and is it the framework’s default? Are migrations versioned in the repository? How do you catch the N+1 problem, with preventLazyLoading or a query log in code review? Where is raw SQL written, and is it parameterized?

Frequently asked questions

What does ORM mean?

In programming, ORM means object-relational mapping: the layer that connects objects in code to the tables of a relational database and writes the routine SQL. In marketing, ORM means online reputation management; the two meanings are unrelated.

Does an ORM make the application slower?

Not for ordinary operations, where the difference is negligible. Slowdowns come from the N+1 problem and from complex reports or large volumes, where an ORM can generate sprawling queries; good teams write those few critical sections directly in SQL and leave the rest of the application to the ORM.

What is the N+1 problem in an ORM?

It is when code runs one query for a list and then one more for each item: 100 orders mean 101 queries instead of two with eager loading. It is fixed with with in Laravel, select_related or prefetch_related in Django, and Include in EF Core.

What are ORM-generated migrations?

They are versioned scripts that change the database structure step by step, in sync with the code. Every environment, from a developer’s laptop to production, reaches the same structure through the same verified steps, which makes a deployment a repeatable operation.

Which ORM do Laravel, Django, Symfony and .NET use?

Laravel uses Eloquent, Symfony uses Doctrine ORM, Django has its own ORM (in Python outside Django, SQLAlchemy is a commonly used alternative), and .NET uses Entity Framework Core. In Java the usual choice is Hibernate, and in Node.js and TypeScript it is Prisma.