rails/rails — pull request #17010 by pvande (2014-09-22 18:12:09+00:00)
Title: Polymorphic `where`s should be treated as a unit.

ActiveRecord's default behavior around `.where.not(hash)` is to ensure that each key is appropriately filtered out from the query, with the effect being that the query is populated with `(key1 != value1) AND (key2 != value2)`. In general, this feels like a fair implementation, despite not being a direct negation of `.where(hash)`.

However, ActiveRecord also supports filtering on a polymorphic association. This works as expected, internally being expanded to a condition that verifies both the relation_id and the relation_type. Negating one of these conditions, however, excludes rows that share a relation_type or a relation_id.

Fixes #16983.