rails/rails — pull request #15772 by nbudin (2014-06-17 17:19:06+00:00)
Title: Don't include inheritance column in the through_scope_attributes

I realize this is probably somewhat a corner case, but the app I work on does have it.

Say you have a model which is an STI subclass, and it contains has_many associations to two other models. From one of those other models, you want to create an association back to the STI subclass, but *only* the subclass, not the base class. Since you really only want the subclass, you name the association after the base class (effectively, the type column becomes a where condition for that association).

You'd also like to get the other objects that are associated through it, so you do a `has_many :through`. Now you want to add an object to that association. Unfortunately this breaks, because as of commit ec0928076529e8f0b5a4ad58c95cfa1fe6ed5b60, Rails attempts to include all the where conditions for the association when building the through object, which ends up including the `type` column. The value of that as returned from `where_values_hash` is an Array, which is fine for querying but not fine for building a new object.

This pull request prevents `through_scope_attributes` from including the inheritance column, which will be set anyway by the association builder.

This affects Rails 4.1.2.rc2, but not 4.1.2.rc1. I have a failing test case against master here: https://gist.github.com/nbudin/74bba7ceb7f2af7b34bb