The time had come to butcher the piggy-back query and introduce real association loading through outer joins. Behold, the glorious eager loading of associations that makes it silly easy to fetch not 1, 2, but unlimited associations alongside any record in a single query. Turning 50 database queries into 1 never felt this good.
# Turning N+1 queries into 1
for post in Post.find(:all, :include => [ :author, :comments ])
puts "Post: " + post.title
puts "Written by: " + post.author.name
puts "Last comment on: " + post.comments.first.created_on
And to match the eager loading, we’re introducing a brand new unified API for Base.find, which works the same whether you’re searching for a specific id, the first record, or all the records. By using named options we alleviate your poor brain for remembering whether the ordering option was argument number 3 or 4.
Person.find(1, :conditions =>"administrator = 1", :order =>"created_on DESC")
Person.find(1, 5, 6, :conditions =>"administrator = 1", :order =>"created_on DESC")
Person.find(:first, :order =>"created_on DESC", :offset => 5)
Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50)
Person.find(:all, :offset => 10, :limit => 10)
We’ve also slashed the huge number of assertions for testing controllers. In one fell swoop, we’ve gone from around thirty to a shap seven. The remaining assertions are more flexible than before, not nearly as hard to remember, and are followed on by the fantastic new assert_tag, which makes examining the HTML output of an action so much easier than the XHTML/REXML fumblings of yesterday.
In the next release, which will be not very far off, we’re also adding awesome support for both Google Suggest-like search boxes and for upload progress indicators. There’s a powerful team behind pushing the envelope on this. We have so not seen the end of it.
A total of 96 changes, tweaks, and fixes
All these goodies are just the tip of the iceberg, though. There’s a total of 96 new features, changes, tweaks, and fixes packed into this monster of a release. And we didn’t even have time to push in all of the pending patches. How’s that for an action-packed three weeks since the last release?
Fully backwards compatible!
Despite the true onslaught of new features, fixes, and goodies, we’ve managed to keep this release fully backwards compatible with 0.11.1. So you just do a “gem update rails” and all the new stuff is available for use in your current application (to take advantage of the new JS effects you’ll want to copy that one over, though — use
rails . in your app dir to get that for free).
See the changelogs for the full story: