Rails4 3階層のincludesの複数指定

N+1問題解決のため、includesの設定をしていた。

groupがuserを参照しており、userがdepartmentとpostを参照しているとき、groupからdepartmentとpostの両方ををincludesで指定するのにちょっと手間取った。

group → user → department・post


下記のように書いたらうまくいった

@groups = Group.order(:id).
                includes({user: [:department, :post]})


関連:
Rails4 3階層のincludesの指定 - ayaketanのプログラミング勉強日記