Rails4 ActiveRecordのincludesで読み込んだ関連の値を利用するためにはreferencesメソッドが必要

Rails4で次のようにActiverecordを書いたら、警告メッセージが表示された。

Post.includes(:comments).where("comments.title = 'foo'")

Rails4からは、読み込んだ関連テーブルの値を利用するためには、referencesメソッドで利用することを明示しなければならないようです。
正しくは、下記のように書く。

Post.includes(:comments).where("comments.title = 'foo'").references(:comments)

実際に表示された警告メッセージは次のようなものでした。

DEPRECATION WARNING: It looks like you are eager loading table(s) (one of: deviations, users) that are referenced in a string SQL snippet. For example:

    Post.includes(:comments).where("comments.title = 'foo'")

Currently, Active Record recognizes the table in the string, and knows to JOIN the comments table to the query, rather than loading comments in a separate query
. However, doing this without writing a full-blown SQL parser is inherently flawed. Since we don't want to write an SQL parser, we are removing this functionality. From now on, you must explicitly tell Active Record when you are referencing a table from a string:

    Post.includes(:comments).where("comments.title = 'foo'").references(:comments)

If you don't rely on implicit join references you can disable the feature entirely by setting `config.active_record.disable_implicit_join_references = true`.

参考:
Rails4へのアップデート時に引っかかったポイントいくつか - Qiita [キータ]