Ruby On Rails 1.1 / bottomless eager loading in Active Record
出てたのに気づかなかった... ^^;
http://weblog.rubyonrails.org/articles/2006/03/28/rails-1-1-rjs-active-record-respond_to-integration-tests-and-500-other-things
あったらいいよねー、と言っていた機能が実装されてる。ActiveRecodのbotomless eager loading、という機能。これにより「オブジェクトの友達の友達の友達...」みたいに、深い階層の関連オブジェクトも一回のsqlでgetできる。つまり、
Bottomless eager loading gives you the power of pulling back a multi-level object graph in a single JOIN-powered SQL query.
こういうこと。例えば、
# Single database query: companies = Company.find(:all, :include => { :groups => { :members=> { :favorites } } })
とcontrollerに書いておけば、ここでsqlが一回実行され
# No database query caused: companies[0].groups[0].members[0].favorites[0].name
こんな感じのアクセスでは、sqlはいちいち実行されない。
いや〜ん。すばらしい。