Active Record
An Active Record Object represents a row in a DB table. The object has fields mapping to a column in the table and methods to access table data.
Active Record connects classes to relational database tables to establish an almost zero-configuration persistence layer for applications.
The library provides a base class that, when subclassed, sets up a mapping between the new class and an existing table in the database.
In the context of an application, these classes are commonly referred to as models.
Models can also be connected to other models; this is done by defining associations.
Active Record objects don’t specify their attributes directly, but rather infer them from the table definition with which they’re linked.
Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects.
The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases but can be overwritten for the uncommon ones.
Use Cases
- Golang
gorm
library is the implementation of the Active Record design pattern. - Ruby gem ActiveRecord