Ruby: Active Record Overview
After a brutal 2 week crash course on Ruby, Active Record became the hero in redeeming Ruby’s challenges for beginners in relation to object-relational mapping (ORM).
What is Active Record?
A team of fed-up developers created the Active Record Ruby gem and Rails Guide defines Active Record below:
“ Active Record is the M in MVC — the model — which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.”
The first week of learning Ruby manually writing out the custom ORM’s was tedious and often led to mistakes. Using Active Record quickly sped up the process with synchronizing data and their respectful tables seamlessly, utilizing one-to-many and many-to-many relationships.
Active Record as an ORM Framework
Rails Guide list the following mechanisms as being the most important within Active Record:
Represent models and their data
Represent associations between these models
Represent inheritance hierarchies through related models
Validate models before they get persisted to the database
Perform database operations in an object-oriented fashion
Convention over Configuration
Active Record follow the paradigm of convention over configuration. For example, one of the most important convention is — class names are singular and table names are plural.
Get courtney’s stories in your inbox
Join Medium for free to get updates from this writer.
Class Name = Artist
Table Name = Artists
To read more about Active Record’s convention over configuration here.
Sum it up!
Knowing the basic mechanics of Active Record will help propel you into more complex web applications that require hefty data and strong communication between your database, client, and servers. Let Active Record do the heavy lifting and improve your productivity with your code!









