They’re a good tool for complex queries.
Simple queries can use the basics of ActiveRecord. The model matches the database table, and operations on the model can mimic the queries on the table. For many operations, this is all you need.
In more complicated scenarios, you will need to join data from two tables and return them in a result set. By mapping the results from a complex query into a result set, you can more easily access and manipulate the data in the rest of your application.
Don’t assemble these maps using a for loop. Instead, return the query results straight into the map, so it lands in the result set in one action.