Why does Rails warn me about an SQL fragment that does not exist?

I am trying to get an application from Rails 3.2 in Rails 4.

One specific point in my code spits out this warning:

DEPRECATION WARNING: It looks like you are eager loading table(s)
(one of: users, one.example) 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`.
(called from authenticate_common at
/path/to/project/app/models/user.rb:72)

But this line does not even contain SQL:

def self.authenticate_common(login, password)
  return nil if login.blank? || password.blank?
  # this line outputs the warning:
  user = User.includes(INCLUDES_FOR_AUTH).where(:login => login).first
  # and so does this line
  user ||= User.includes(INCLUDES_FOR_AUTH).where(:email => login).first
  return nil unless user && user.authenticated?(password)
  user
end

Not only the condition here is not used by SQL, but does not even refer to any related models, so the proposed fix cannot be performed. In addition, the class has Userno scope that could add any default conditions.

Value INCLUDES_FOR_AUTH:

INCLUDES_FOR_AUTH = [{ :roles => [ :permissions ]}]

There are also no SQL fragments in the classes Roleand Permission, therefore, they cannot be.

, , , Rails SQL, ... , ?:/

:

  • , [], .
  • order .
  • references(:user) , . , , , , references, , , .
  • , , , , , :

    SELECT 1 AS one FROM "users" WHERE "users" . "login" = 'someone@somewhere.com' LIMIT 1
    SELECT 1 AS one FROM "users" WHERE "". "Email" = "someone@somewhere.com" LIMIT 1

    , where , , , , SQL Rails.

+4

All Articles