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 scoped has_one
assocation.
View the source code:
Read the blog post explaining this approach.
Author | Newest Post | Published |
---|---|---|
J.D. Salinger | Franny and Zooey | 1961-01-01 |
Jane Austen | Persuasion | 1817-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.