ActiveRecord

Ramazan Ramazanov
2 min readJan 9, 2021

Of course, some people will be in love with SQL for the first time as it is easy to learn and to use. SQL (standard query language) is a standard language to store, manipulate and retrieve data in databases. But with the use of ActiveRecord these functions get even easier. For example, if I want to get an array containing a listing of all the users, instead of writing code to initiate a connection to the database, then doing some sort of SELECT * FROM users query, and converting those results into an array, I can just type User.all and Active Record gives me that array filled with User objects that I can play with as I’d like. Isn’t it great?

ActiveRecord is actually a Ruby gem that takes care of the stuff in the database. It is also known as ORM or Object-Relational-Mapping. It takes the stored data in a database table using rows and columns, which needs to be modified or retrieved by writing SQL statements (if you are using a SQL database) and it lets you interact with that data as a normal Ruby object.

Using ActiveRecord sometimes gets so impressive that it does not matter which type of database you use. It will smooth out all the differences between those databases for you so you do not have to think about them. ActiveRecord is that type of your helper that will think about the nitty gritty details of connecting you to your database and the only thing required from you is to focus on writing code for your application. Even if you change or switch from one database to another, you do not need to change any major application code, except for some configuration files.

By running $ gem install activerecord you can install the gem and enjoy the miracle of ActiveRecord. The prime directive has been to minimize the amount of code needed to build a real-world domain model.

--

--