Archive for January 27, 2016
-
Unit Testing ActiveRecord eager-loading
January 27, 2016
If you’ve worked with relational databases and any ORMs like Java’s Hibernate, .NET’s NHibernate or Rails’
ActiveRecord
in the past, you might be familiar with SELECT N+1 issues. It is a common performance problem in database-dependent applications and, because of this, these ORMs provide a built-in solution to this problem.In
ActiveRecord
,includes
,preload
andeager_load
come to the rescue. Therefore, it is not unusual to find these keywords scattered in different places where your application accesses the database. Hopefully this isn’t a lot of places though - you are using Query Objects, right?An example application
Let’s imagine for a second that we have an application where you can browse restaurants, which in turn have many reviews…