Active Record is a popular Object Relational Mapping system (ORM) that many web developers find themselves using at some point or another. A lot has been said about the benefits and drawbacks of ORMs in general, and Active Record shares all of them. Regardless of how you feel about it, using Active Record will be […]
Rails and Active Record make many things easy: connecting to the database, building complex queries based on your object model, and easily migrating your schema up, down, and sideways. They also let you very easily introduce N+1 queries.
I was recently working on a piece of code from a legacy Rails application. An unusually large number of queries being run on a particular page let me know there was an N+1 query lurking. The application was an online assessment platform dealing with assessments, questions, and responses. The question listing page was simply asking […]
Every Rails project I’ve worked on has used Active Record. ORMs like Active Record have many benefits. They abstract you away from the database. They make querying data elegant and simple (in most cases). However, sometimes Active Record is not more efficient than Postgres.