Cascaded eager loadingでの注意点

めっちゃすごいけど、何も考えずに使いすぎるのもよくない。まだできないことや注意点もあるので、メモしておく。

ソースコード内のコメントより

gems/activerecord-1.14.2/lib/active_record/associations.rb

has_many,has_and_belongs_to_manyを利用するとき、:conditionsはコンパチでない。

Please note that limited eager loading with has_many and has_and_belongs_to_many associations is not compatible with describing conditions on these eager tables

他にも、:orderを利用するときにも注意が必要。カラム名をユニークに指定すること。

eager loading is pulling from multiple tables, you'll have to disambiguate any column references in both conditions and orders.
So :order => "posts.id DESC" will work while :order => "id DESC" will not

そして、(僕がハマったとこだが)まだ、同一テーブルからのmultiple associationには対応していない。(これをやると、「ambiguousカラム名が指定されてるよー」みたいな文句を言われる)

It's currently not possible to use eager loading on multiple associations from the same table.

だから、has_and_belongs_to_manyの上のrich associationsと、eager loadingの併用はキケン。

Eager loading will not pull additional attributes on join tables, so "rich associations" with has_and_belongs_to_many is not a good fit for eager loading.