rails/rails — pull request #12873 by martinemde (2013-11-13 19:43:04+00:00)
Title: Fix AR:B.where(belongs_to_assoc: nil) which generated invalid SQL

When referring to a belongs_to association in a query, nil values
would cause the PredicateBuilder to skip over the part that expanded
the association name into the foreign key.

For example:

Post.where(author: nil)

This should return posts where the author is not set, but instead
it generates an invalid SQL statement using the association name.

# Invalid SQL generated previousl
SELECT "posts".* FROM "posts" WHERE "posts"."author" IS NULL

This fix removes the requirement that the association value is an
ActiveRecord::Base object when converting the association name to its
respective foreign key.

# New valid SQL returning the expected result.
SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL