Overview
Active Record is the model layer of Ruby on Rails and an implementation of the pattern Martin Fowler described as an object that wraps a database row and adds domain logic. Models inherit from ApplicationRecord, map to tables by naming convention, and gain query methods (where, order, joins, includes), validations, callbacks and associations such as has_many, belongs_to and has_many :through, plus single-table inheritance.
Migrations are Ruby classes (for example ActiveRecord::Migration[8.1]) that describe schema changes with a database-independent DSL; running them updates db/schema.rb, which records the current structure. Generators create models and migrations together.
Because it follows convention over configuration, a Rails app needs very little mapping code, but it also means Active Record is designed for use inside Rails. Sequel is the main standalone alternative in Ruby.
Before you pick it, know what it is not: Active Record ties each model to one table and puts behaviour on the model, so business rules, validations and persistence live together. The Rails guides recommend reading the associations and migrations guides alongside the basics, and most of the query performance work in Rails apps comes down to using includes or strict loading to avoid N+1 queries.
Pricing and plans
| Plan | Price | What you get |
|---|---|---|
| Active Record | $0 | Part of the MIT-licensed Ruby on Rails framework |
What it does
- Convention over configuration
- Table, key and column names follow Rails conventions, so models need almost no mapping code.
- Associations
- belongs_to, has_one, has_many, has_many :through, has_and_belongs_to_many and polymorphic associations.
- Validations and callbacks
- Declarative validations and lifecycle callbacks run before and after saves.
- Query interface
- Chainable where, order, joins, includes and scopes that build SQL lazily.
- Migrations
- Ruby DSL migrations with reversible change methods; db/schema.rb reflects the result.
Strengths and limitations
Strengths
- Extremely fast to build with inside Rails
- Mature, with decades of production use and extensive guides
- Migrations and schema file kept in step automatically
- Large gem ecosystem built around it
Limitations
- Designed for Rails; using it standalone is uncommon
- Callbacks and fat models can make large codebases hard to follow
- N+1 queries appear easily without includes or strict loading
- Models are tied to the database schema, as the Active Record pattern implies
Who it suits
Good for
- Ruby on Rails applications
- Startups that want to ship CRUD features quickly
- Teams already fluent in Rails conventions
Look elsewhere if
- Non-Rails Ruby services (Sequel fits better)
- Domain models that need to stay independent of persistence
Alternatives to Active Record (Rails)
| Tool | From | Free option | Stages |
|---|---|---|---|
| Eloquent ORM Active Record ORM for Laravel | — | ||
| SQLAlchemy Python SQL toolkit and ORM | — | ||
| Entity Framework Core .NET ORM | — | ||
| Dapper .NET micro-ORM | — | ||
| Prisma ORM Schema-first TypeScript ORM | $10/mo | Free tier | |
| TypeORM Decorator-based TypeScript ORM | — |
Questions
What is Active Record in Rails?
It is the Rails ORM: models that wrap database tables and add associations, validations and callbacks.
How do migrations work in Rails?
Migrations are Ruby classes that change the schema through a DSL; running them updates db/schema.rb.
Can I use Active Record without Rails?
Yes, the gem can be used on its own, but most documentation and tooling assume a Rails app.
Sources read for this page