This view shows a list of authors along with the title of their newest post and the date that it was published. It implements a Greatest Per Group query – thus, avoiding the N+1 query problem – using a View Backed Model.
View the source code:
Read the blog post explaining this approach.
|J.D. Salinger||Franny and Zooey||1961-01-01|
|Charles Dickens||Barnaby Rudge||1841-01-01|
This Ruby on Rails app demonstrates the concepts encompassed in a series of blog posts about Greatest Per Group queries in Rails. You can view the source code on Github.