rails/rails — pull request #10366 by schuetzm (2013-04-27 14:54:58+00:00)
Title: Fix where with polymorphic relation

Say you have classes like this:

```
class Dog < ActiveRecord::Base
has_many :tags, as: :owner
end

class Cat < ActiveRecord::Base
has_many :tags, as: :owner
end

class Tag < ActiveRecord::Base
belongs_to :owner, polymorphic: true
end
```

then this works correctly:
```
Tag.where(owner: Cat.find(42))
=> SELECT "tags".* FROM "tags" WHERE "tags"."owner_type" = 'Cat' AND "tags".owner_id = 42
```

However, using a relation as the find value produces an incorrect query:
```
Tag.where(owner: Dog.all)
=> SELECT "tags".* FROM "tags" WHERE "tags"."owner" IN (SELECT "dogs"."id" FROM "dogs")
```

As you can see, there's no test for the correct ```owner_type``` in the second query, and it uses a non-existing column ```owner```.

The referenced changes fix that problem (failing test included).