I'm upgrading a project from Rails 3.2 to Rails 4.0, and I'm trying to fix a problem that is causing a deprecation warning. The warning is caused by a query like this one:
email = Email.
includes(:person).
where("lower(email) = ? ", login_email.downcase).
first
Here the "emails" table has a string column "email" that holds the email address.
The deprecation warning is the Rails 4 one that says that since I am using where() with a SQL string and I am using includes() to eager-load, I should use references() to do a proper job of joining, so that rails doesn't have to parse the SQL to figure out the join. In this case, the SQL I am using references the model I am querying from, not an association, so there is no join involved with the SQL. To silence the warning, I was tempted to do the following bit of nonsense, saying that the join reference is the querying model:
email = Email.
includes(:person).
where("lower(email) = ? ", login_email.downcase).
references(:emails).
first
But this does not silence the deprecation warning.
The problem in a nutshell: I am calling where() with SQL that references the model I am querying from, I am using includes() to eager-load data from a table that is unrelated to the aforementioned SQL, but I am being asked to use references() in a situation where it doesn't apply.
Any tips on how to fix the problem that causes the deprecation warning in this case? The tip supplied by the warning itself doesn't really apply here.
Cheers, Chris